Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

794 Communicating with a Network Printer Chapter 21


chapter,our interest is not in these spooling systems per se, but rather in
communicating with a network printer.Weneed to develop a spooling system to solve
the problem of multiuser access to a single resource (the printer).
We use a simple command that reads a file and sends it to the printer spooler
daemon. The command has one option to force the file to be treated as plaintext (the
default assumes that the file is PostScript).We call this commandprint.
In our printer spooler daemon,printd, we use multiple threads to divide up the
work that the daemon needs to accomplish.

•One thread listens on a socket for new print requests arriving from clients
running theprintcommand.
•Aseparate thread is spawned for each client to copy the file to be printed to a
spooling area.
•One thread communicates with the printer,sending it queued jobs one at a time.
•One thread handles signals.

Figure21.6 shows how these components fit together.

file to
print

print
command

printd
printer
spooler

file 1 file 2 file 3
config file

printer

queue of files to be printed

Figure 21.6 Printer spooling components

The print configuration file is/etc/printer.conf.Itidentifies the host name of
the server running the printer spooling daemon and the host name of the network
printer.The spooling daemon is identified by a line starting with theprintserver
keyword, followed by white space and the host name of the server.The printer is
identified by a line starting with theprinterkeyword, followed by white space and
the host name of the printer.
Asample printer configuration file might contain the following lines:
printserver fujin
printer phaser8560
wherefujinis the host name of the computer system running the printer spooling
daemon, andphaser8560is the host name of the network printer.Weassume these
Free download pdf