📄 ch39.htm
字号:
device (<TT>b</TT>), character mode device (<TT>c</TT>), FIFO device (<TT>p</TT>),
or unbuffered character mode device (<TT>u</TT>). One of these arguments must be
present on the command line.</P>
<P>Following the type of file argument are two numbers for the major and minor device
numbers assigned to the new file. Every device on a UNIX system has a unique number
that identifies the type of device (the major number) and the specific device itself
(the minor number). Both a major and a minor number must be specified for any new
block, character, or unbuffered mode device. Device numbers are not specified for
a type <TT>p</TT> device.</P>
<P>Examples of using the <TT>mknod</TT> command are shown in several sections later
in this chapter, when devices are added to the system.
<CENTER>
<H3><A NAME="Heading7<FONT COLOR="#000077">Printer Administration</FONT></H3>
</CENTER>
<P>Printers are commonly used devices that can cause a few problems for system administrators.
They are quite easy to configure as long as you know something about the hardware.
Managing printer queues is also quite easy, but like many things in Linux, you must
know the tricks to make the system work easily for you.</P>
<P>Linux is based on the BSD version of UNIX, which unfortunately is not the most
talented UNIX version when it comes to printer administration. However, because it's
unlikely that the Linux system will be used on very large networks with many printers,
administration tasks can be reduced to the basics. Be warned, though, that the BSD
UNIX printer administration and maintenance commands have a reputation for quirky
and inconsistent behavior!
<CENTER>
<H4><A NAME="Heading8<FONT COLOR="#000077">The lpd Printing Daemon</FONT></H4>
</CENTER>
<P>All printing on the Linux system is handled by the <TT>lpd</TT> daemon, which
is usually started when the system boots. During the startup process, the <TT>lpd</TT>
daemon reads through the file <TT>/etc/printcap</TT> to identify the sections that
apply to any of the printers known to be attached to the system. The <TT>lpd</TT>
daemon uses two other processes, called listen and accept, to handle incoming requests
for printing and to copy them to a spooling area.</P>
<P>In most cases, you won't have to modify the <TT>lpd</TT> daemon. However, there
might be times when you have to stop it manually and restart it. The command to load
<TT>lpd</TT> is<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpd [-l] [port]
</FONT></PRE>
<P>The <TT>-l</TT> option invokes a logging system that notes each print request.
This option can be useful when you're debugging the printer system. The port number
allowed in the <TT>lpd</TT> command line is used to specify the Internet port number
if the system configuration information is to be overridden. You will probably never
have to use it.</P>
<P>The size of the print spool area is set by an entry in the file <TT>minfree</TT>
in each spool directory (each printer has its own spool directory). The contents
of <TT>minfree</TT> show the number of disk blocks to keep reserved so that spooling
large requests doesn't fill up the hard drive. The contents of the file can be changed
with any editor.</P>
<P>Access to the <TT>lpd</TT> daemon to allow printing of a user request must pass
a quick validation routine. Two files are involved: <TT>/etc/hosts.equiv</TT> and
<TT>/etc/hosts.lpd</TT>. If the machine name of the sending user is not in either
file, the print requests are refused. Because the local machine is always in <TT>hosts.equiv</TT>
(as <TT>localhost</TT>), users on the Linux machine should always have their print
requests granted.
<CENTER>
<H4><A NAME="Heading9<FONT COLOR="#000077">Following a Print Request</FONT></H4>
</CENTER>
<P>To understand how the print daemon works, as well as how print requests are managed
by Linux, it is instructive to follow a print request. When a user requests a print
job with the <TT>lpr</TT> command, <TT>lpr</TT> assembles the data to be printed
and copies it into the spooling queue, where <TT>lpd</TT> can find it.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading10<FONT COLOR="#000077"><B>NOTE: </B></FONT>The <TT>lpr</TT>
program is the only one in the Linux system that can actually queue files for printing.
Any other program that offers printing capabilities does so by calling <TT>lpr</TT>.
<HR>
</DL>
<P>As part of its spooling task, <TT>lpr</TT> also checks for instructions on how
to print the file. It can get the information from three sources: the command line
(supplied as arguments), environment variables (set by the shell or the user), or
the system's default values.</P>
<P>The <TT>lpr</TT> program knows which spool to put the print request in because
of the destination printer designation. The printer destination can be specified
on the <TT>lpr</TT> command line, or through an environment variable. When the destination
printer name has been determined, <TT>lpr</TT> checks the file <TT>/etc/printcap</TT>
to look up the printer's information, including the spool directory. The spool directory
is usually of the form <TT>/usr/spool/printer_name</TT>, such as <TT>/usr/spool/lp1</TT>.</P>
<P>Within the spool directory, <TT>lpr</TT> creates two files. The first has the
letters <TT>cf</TT> (control file) followed by a print ID number. The <TT>cf</TT>
file contains information about the print job, including the owner's name. The second
file starts with <TT>df</TT> (data file) and has the actual contents of the file
to be printed with it. When <TT>lpr</TT> has finished creating the <TT>df</TT> file,
it sends a signal to <TT>lpd</TT> that informs the daemon that a print job is waiting
in the spool directory.</P>
<P>When <TT>lpd</TT> gets the signal from <TT>lpr</TT>, it checks the file <TT>/etc/printcap</TT>
to see whether the printer is for a local or remote printer. If the print job is
for a remote printer (one attached to another machine on the network), <TT>lpd</TT>
opens a connection to the remote machine, transfers both the control and data files,
and deletes the local copies.</P>
<P>If the print job is for a local printer, <TT>lpd</TT> checks to make sure the
printer exists and is active, and then sends the print request to the printing daemon
running that queue.
<CENTER>
<H4><A NAME="Heading11<FONT COLOR="#000077">The /etc/printcap File and Spooling
Directories</FONT></H4>
</CENTER>
<P>The <TT>/etc/printcap</TT> file is consulted by both the user's print command
<TT>lpr</TT> and the <TT>lpd</TT> print daemon. It contains information about every
printer that is accessible from the Linux machine.</P>
<P>The format of <TT>/etc/printcap</TT> is straightforward (and similar to the <TT>/etc/termcap</TT>
file for terminal descriptions). The following is an extract from <TT>/etc/printcap</TT>:<FONT
COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF"># HP Laserjet
lp|hplj|laserjet-acctng|HP LaserJet 4M in Room 425:\
:lp=/dev/lp0:\
:sd=/usr/spool/lp0:\
:lf=/usr/spool/errorlog:\
:mx#0:\
:of=/usr/spool/lp0/hpjlp:\
</FONT></PRE>
<P>The first field in each entry is a list of all the allowable names for the printer.
These can be used with the environment variables set by a user's shell or by the
system, as well as with options on the <TT>lpr</TT> command line with a destination
printer specified. Valid names are separated by a vertical bar.</P>
<P>Usually, each entry includes at least three names: a short name that is four characters
or less (such as <TT>hplj</TT>); a more complete name with an owner, if necessary
(such as <TT>laserjet-acctng</TT>); and a full, descriptive name with any other information
necessary to identify the printer (such as <TT>HP LaserJet 4M in Room 425</TT>).
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading12<FONT COLOR="#000077"><B>NOTE:</B> </FONT>If a print job
is submitted without a destination name, and one can't be determined from environment
variable values, it is routed to the printer <TT>lp</TT>. Therefore, one of the printers
(usually the system default printer) should also have the name <TT>lp</TT> as part
of its identifier.
<HR>
</DL>
<P>A comment in the file is shown with a pound symbol (sometimes called a hash mark)
as the first character. Following the printer name is a set of two-character parameters
and values used by the printer. The format of these entries is always one of the
following:
<TABLE BORDER="0">
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="71" ALIGN="LEFT">NN </TD>
<TD ALIGN="LEFT">A Boolean value </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="71" ALIGN="LEFT">NN<TT>=</TT>string </TD>
<TD ALIGN="LEFT">Set equal to <TT>string</TT> </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="71" ALIGN="LEFT">NN<TT>#</TT>number<BR>
</TD>
<TD ALIGN="LEFT">Set not equal to <TT>number<BR>
</TT></TD>
</TR>
</TABLE>
When a Boolean value is used (no assignment follows the two-character identifier),
the value is set to True by default. If the value of False was required, the two-character
identifier would not be included in the description.</P>
<P>Most assignments are shown with colons beginning and ending each definition to
enhance readability and make the file easier for the print utilities to parse. Null
values are valid assignments employed by putting two colons together.</P>
<P>A few of the parameters in the <TT>/etc/printcap</TT> file are worth highlighting
because they are useful for administration purposes. Not all of these parameters
might be present in every printer definition in the <TT>/etc/printcap</TT> file,
but most appear:
<TABLE BORDER="0">
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="35" ALIGN="LEFT"><TT>sd</TT> </TD>
<TD ALIGN="LEFT">The spool directory </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="35" ALIGN="LEFT"><TT>lf</TT> </TD>
<TD ALIGN="LEFT">The log directory for error messages </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="35" ALIGN="LEFT"><TT>af</TT> </TD>
<TD ALIGN="LEFT">Accounting log file </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="35" ALIGN="LEFT"><TT>mx</TT> </TD>
<TD ALIGN="LEFT">Determines the type of files that can be printed </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="35" ALIGN="LEFT"><TT>of<BR>
</TT></TD>
<TD ALIGN="LEFT">Output filter program to be used when printing<BR>
</TD>
</TR>
</TABLE>
<P>All printers should have their own spool directories, usually under the printer
name in <TT>/usr/spool</TT>, such as <TT>/usr/spool/hplj</TT>. Spool directories
are necessary for both remote and local printers. When a new printer is added to
the system, the spool directory might have to be created manually (using <TT>mkdir</TT>).
The permissions for the spool directory should be set to 775. The directory must
be owned by <TT>root</TT> or <TT>daemon</TT>. The group ID should be set to <TT>root</TT>
or <TT>daemon</TT>, too. In both cases, <TT>daemon</TT> theoretically is the better
ID for user and group, although <TT>root</TT> will work also.</P>
<P>The error log file can be located anywhere on the system. It can be shared by
all printers, if desired, because each log entry includes the name of the printer.</P>
<P>The accounting log file is used to record printouts for systems in which users
are charged. If accounting records are not to be used on the system, ignore the entry
entirely in the <TT>/etc/printcap</TT> file. The file can also be used for generating
statistics, however. Some heavily used systems might want to have the accounting
file for those purposes even when charges are not incurred by the users. An entry
is written to the accounting log file after a print job has completed. Account information
can be displayed with the Linux <TT>pac</TT> command. (Use the <TT>man pac</TT> command
to display the man pages for more information about <TT>pac</TT>.)</P>
<P>The <TT>mx</TT> character enables you to identify the types of files to be printed.
Usually this is set to <TT>mx#0</TT>, meaning that there are no restrictions on the
types of files.</P>
<P>Output filters modify the format of the outgoing file to the printer to fit its
requirements. For example, many laser printers can't handle 66 lines per page, so
the output filter repaginates to 60 lines (or whatever the number of lines per page
is set to). Sometimes, special codes must be added to force line feeds, font changes,
or paper bin selections. All these items are part of the output filter. Several other
types of filters are available, but the output filter is the one most commonly encountered.</P>
<P>Within each spool directory, there may be two status files: <TT>status</TT> and
<TT>lock</TT>. Each file is one line long and can be modified with an editor. These
files contain a description of the current state of the printer. They are created
and managed by the <TT>lpd</TT> printer daemon and used by several printer commands
for status information.
<CENTER>
<H4><A NAME="Heading13<FONT COLOR="#000077">Adding Printer Devices with mknod</FONT></H4>
</CENTER>
<P>Linux supports both parallel and serial printer devices. Both parallel and serial
printers are character mode devices. Unfortunately, most Linux distributions do not
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -