A Guide to the Lp

Printer Spooler

Paul Glick

pg@plan9.bell-labs.com

ABSTRACT

Lp is a collection of programs used to provide an easy-to-use interface for printing a variety of document types on a variety of printers. Lp is the glue that connects various document language translators and printer communication programs together so that the users may have a consistent view of printers. Most of the glue is shell script, which can be easily modified. The user need not specify options to get sensible output in most cases. Lp is described here so that others may make additions and changes.

1. Introduction

Lp is used to format and print data on a variety of output devices. The need for lp was rooted in the inability of other printer spoolers to do simple tasks without a great deal of user specification of options. At the time lp was written, there were several printer languages, such as ImPress and PostScript, and an internally developed printer that would accept troff output. Now, all our printers take PostScript, but printers that use HPCL and HPGL abound and support for those printers may be added easily. A great deal of what underlies lp is taken from BSD’s lpr and System V’s lp. The important features of this system are that most of the programs are easily modified shell scripts and the user need not learn to use the large amount of underlying software developed by others. Lp runs under Plan 9 and several flavors of UNIX. This document deals with lp as it relates to Plan 9. Lp was developed using both Datakit and Ethernet to transport data between machines. Now only the Ethernet transport mechanism remains.

Text, graphics, and formatted text files are appropriately processed and placed into a spool directory from which they are taken to be printed by a daemon process. Additional functions include checking the status of a printer queue and removing jobs from the printer queue.

All the shell scripts (see rc(1)) associated with lp reside in the spool directory /sys/lib/lp except for the lp command itself, which resides in /rc/bin. Commands related to lp that are not shell scripts can most often be found in /$cputype/bin/aux. The directory where all the lp scripts reside is defined within lp by the shell variable LPLIB. In the remainder of this document, file names will be specified with this shell variable as their root.

2. Usage

Lp requires an output device to be specified before it will process input. This can be done in any of three ways described here.

1) The file $LPLIB/defdevice may contain the name of a default output device. This may not be practical for environments where there are many printers.

2) The user’s environment variable LPDEST may be set to the name of the device to be used. This is often a more practical solution when there are several printers available. This overrides a defdevice specification.

3) The -d printer option to the lp command specifies printer as the device to which output should be directed, overriding the previous two specifications.

If printer is ?, a list of printers and other information in the devices file is printed, as shown in Figure 1. Quote the question mark to prevent it from being interpreted by the shell language as a metacharacter.

% lp -d’?’

device   location  host             class

fn       2C-501    helix            post/2+600dpi+duplex

pcclone  -         -                post+nohead

peacock  2C-501    cetus            post/2+300dpi+nohead+color

ps83     st8_fl3   rice             post+300dpi+reverse

psu      2C-501    cetus            post/2+1200dpi

     .

     .

     .

%

Figure 1. Sample listing of installed printers

Normally, lp uses the file command to figure out what type of input it is receiving. This is done within the generic process which is discussed later in this paper in the Process directory section. To select a specific input processor the -pprocess option is used where process is one of the shell scripts in the process directory.

Troff output can be printed, in this case, on printer fn with

% troff -ms lp.ms | lp -dfn

A file can be converted to PostScript using the pseudo-printer stdout:

% troff -ms lp.ms | lp -dstdout > lp.ps

LaTeX (and analogously TeX) documents are printed in two steps:

% latex lp.tex

     .

     .

% lp lp.dvi

     .

     .

%

LaTeX produces a ‘.dvi’ file and does not permit the use of a pipe connection to the standard input of lp. To look at the status and queue of a device, use -q:

% lp -dpsu -q

daemon status:

:  67.17% sent

printer status:

%%[ status: busy; source: lpd ]%%

queue on cetus:

job     user    try size

rice29436.1 pg  0   17454

slocum17565.1   ches    1   49995

%

This command can print the status and queue of the local and remote hosts. Administrators should be advised that working in an environment where the lp spool directory is shared among the local and remote hosts, no spooling should be done on the local hosts. The format of the status and queue printout is up to the administrator. The job started above can be killed with -k:

$ lp -dpsu -k rice29436.1

rice29436.1 removed from psu queue on cetus

3. Options

There are options available to modify the way in which a job is handled. It is the job of the lp programs to convert the option settings so they may be used by each of the different translation and interface programs. Not all options are applicable to all printer environments. Table 1 lists the standard lp options, the shell variable settings, and description of the options.

Table 1. Lp Option List

4. Devices file

The devices file is found in the spool directory. Each line in the file is composed of 12 fields, separated by tabs or spaces, that describe the attributes of the printer and how it should be serviced. Within the lp command, a shell variable is set for each attribute; the following list describes them:

LPDEST is the name of the device as given to lp with the -d option or as specified by the shell environment variable LPDEST or as specified by the file $LPLIB/defdevice. This name is used in creating directories and log files that are associated with the printers operation.

LOC just describes where the printer is physically located.

DEST_HOST is the host from which the files are printed. Files may be spooled on other machines before being transferred to the destination host.

OUT_DEV is the physical device name or network address needed by the printer daemon to connect to the printer. This field depends on the requirements of the daemon and may contain a ‘–’ if not required.

SPEED is the baud rate setting for the port. This field depends on the requirements of the daemon and may contain a ‘–’ if not required.

LPCLASS is used to encode minor printer differences. The keyword reverse is used by some of the preprocessors to reverse the order the pages are printed to accommodate different output trays (either face up or face down). The keyword nohead is used to suppress the header page. This is used for special and color printers. The keyword duplex is used to coax double sided output from duplex printers.

LPPROC is the command from the LPLIB/process directory to be used to convert input to a format that will be accepted by the device. The preprocessor is invoked by the spooler.

SPOOLER is the command from the LPLIB/spooler directory which will select files using the SCHED command and invoke the LPPROC command, putting its output into the remote spool directory. The output is sent directly to the spool directory on the destination machine to avoid conflicts when client and server machines share spool directories.

STAT is the command from the LPLIB/stat directory that prints the status of the device and the list of jobs waiting on the queue for the device. The status information depends on what is available from the printer and interface software. The queue information should be changed to show information useful in tracking down problems. The SCHED command is used to show the jobs in the order in which they will be printed.

KILL is the command from the LPLIB/kill that removes jobs from the queue. The jobs to be removed are given as arguments to the lp command. When possible, it should also abort the currently running job if it has to be killed.

DAEMON is the command from the LPLIB/daemon that is meant to run asynchronously to remove jobs from the queue. Jobs may either be passed on to another host or sent to the printing device. Lp always tries to start a daemon process when one is specified.

SCHED is the command from the LPLIB/sched that is used to present the job names to the daemon and stat programs in some order, e.g., first-in-first-out, smallest first.

5. Support programs

The following sections describe the basic functions of the programs that are found in the subdirectories of $LPLIB. The programs in a specific directory vary with the type of output device or networks that have to be used.

5.1. Process directory

The generic preprocessor is the default preprocessor for most printers. It uses the file(1) command to determine the format of the input file. The appropriate preprocessor is then selected to transform the file to a format suitable for the printer.

Here is a list of some of the preprocessors and a description of their function. A complete list of preprocessors and their descriptions can be found in the manual page lp(8).

dvipost Converts TeX or LaTeX output (.dvi files) to PostScript

ppost Converts UTF text to PostScript. The default font is Courier with Lucida fonts filling in the remainder of the (available) Unicode character space.

tr2post Converts (device independent) troff output for the device type utf. See /sys/lib/troff/font/devutf