Previous | Next

Objectives| Introduction| Hardware| Software| The SysV Print Software| The BSD Print Software| /etc/printcap| The BSD Print Commands| Conclusions| Review Questions

Section 11


PRINTERS


Objectives


By the end of this section you should

Introduction


Printers are a standard peripheral for any computer system. One of the first devices added to a new system will be a printer. The multi-user nature of the UNIX operating system means that the UNIX printer software is more complex than that of a single-user operating system. This makes adding a printer to a UNIX box more than just plugging it in.

UNIX print software performs a number of tasks including

This section will first examine the hardware issues involved in connecting a printer to a UNIX machine before moving on to examine the more complex part of the process, configuring the software.


Hardware


In most situations printers are connected to a UNIX machine using serial connections. Many modern systems provide parallel ports. Generally speaking connecting a printer to a UNIX system follows the same generic process used to connect terminals that was outlined in Figure 10.1.


Choose a Port


Typically you will have two choices with printers, either parallel or serial ports depending on your printer. The details of cabling for serial ports were discussed in the previous section.


Test the Connection


Performed the same way as that for terminals. Simply send output to the device file associated with the new device. Figure 11.1 outlines some possible reasons why it might not work as expected.
Exercise 11.1. If possible go through the hardware procedure for connecting a printer to your UNIX box.


Software


The software that drives the UNIX printing process is another area in which the different UNIX versions differ greatly. Both versions are based on the concept of spooling (spool stands for Simultaneous Peripheral Operations On-Line).

All UNIX print software has at least the following two components

For every printer there will always be a maximum of one print daemon. This ensures that only one document is being printed on any printer.

Both SysV and BSD print services also support the concept of an interface program. This program acts as a filter through which all output sent to the printer is passed through. Example uses of an interface program include


The SysV Print Software


The SysV print system uses a number of definitions. Table 11.1 summarises some of them.
		Term	Definition

		device	the actual physical printer
		printer	the interface program/connection to the device
		class	a group of similar printers known by one name

			Table 11.1. System V Printer Definitions.
The entire spooling system is a complex system. The following diagram provides a simplification of the systems operation.

Image

Diagram 11.1. System V Print Spooling System.

lpsched is the name of the daemon that is continually running and provides the "power" for the print service. Only one copy of lpsched should be running at any one time. There should be a file SCHEDLOCK in /usr/spool which is responsible for ensuring only one copy runs.

lpshut turns off the print service by killing the lpsched daemon. Print jobs can still be spooled while lpsched is not running but they won't be printed. You should always run lpshut before using lpadmin.

	Command		Purpose

	accept/reject	allows/disallows any further requests for a printer
			  or class entering the spooling area
	cancel		allows user to stop the printing of information
	enable/disable	allow/disallow any more output from the spooler to
			  the printer
	lpmove		move print requests between destinations
	lp		THE USER'S PRINT COMMAND, places information to be
			  printed into the spooler
	lpadmin		allows the configuration of the print service
	lpsched		start the print service
	lpshut		stop the print service
	lpstat		display status of the print service

		Table 11.2. System V Print Service Commands.

Steps For Connecting a Printer under SysV


The following summarises the steps involved in adding a printer to a SysV system.

The BSD Print Software


The major components of the BSD print system are listed in Table 11.3. An overview of the system is provided by Diagram 11.2.
	Component	Purpose

	lpc		make administrative changes to the print service
	lpd		the daemon, a copy is spawned for each queue,
			  transfers information from spooling area to
			  physical device
	lpq		view the contents of a print queue
	lpr		the user print command, spools information to
			  be printed
	/etc/printcap	system's printer information database
	lprm		removes print jobs from queues

		Table 11.3. BSD Print Service Components.

Image

Diagram 11.2. BSD Print Service.

Each printer connected to a BSD system must have its own spooling directory that is serviced by one lpd daemon. Each printer has its own lpd daemon.

lpd accesses the file /etc/printcap for any information it requires concerning the printer. /etc/printcap is the system's printer database file and stores all the necessary information about ALL printers connected to the system. To use a printer, that printer must have an entry in /etc/printcap.

lpr is BSD's equivalent to lp under System V. If a user wishes to print something they use lpr. lpr sends this information to a specified spooling directory.

The process for adding a printer to a BSD system is somewhat similar to that for SysV.


Steps for connecting a printer under BSD


The following summarises the steps involved in adding a printer to a BSD system.

/etc/printcap


This file contains a colon delimited entry for every printer connected to the system. The entry for each printer contains fields for The configuration settings are used to specify a variety of different printer settings. Table 11.4 provides a list of some of the information specified in /etc/printcap.

The configuration settings can take one of three possible formats

Where XX is a two letter identifier for the particular configuration setting.

For example:

	Specify the location of the spool directory for a printer
		sd=/usr/spool/lp/scribe
	Force a form feed when the device is first opened
		fo
	Specify the maximum size (in blocks) of files that can be printed
		mx#3


	Setting		Purpose

	sd=directory	specify spool directory
	lf=file		specify error log file
	lp=file		specify device file
	af=file		specify accounting file
	rw		specify that printer can both read and write
			  infomation (can send status info back to computer)
	br#number	specify baud rate
	fc#number *	specify flag bits to turn off
	fs#number *	specify flag bits to turn on
	xc#number *	specify local mode bits to turn off
	xs#number *	specify local mode bits to turn on
	pl#number	specify page length in lines
	pw#number	specify page width in characters
	py#number	specify page height in pixels
	px#number	specify page width in pixels
	ff=string	specify string that causes printer to form feed
	fo		output form feed when device is opened
	mc#number	specify maximum number of copies of a job allowed
	mx#number	specify maximum file size in blocks allowed
	sc		specify that multiple copies should be prevented
	sf		specify that form feeds should be prevented
	sh		suppress the printing of headers

		* see explanation below

		Table 11.4. Configuration Settings for /etc/printcap.

Flag Bits


Flag bits are used to specify various communication settings for the printers. Table 11.5 shows the meanings and octal values of the more important bits.
The flag bits that are to be turned on are specified using the fs identifier (see Table 11.4). Those flag bits to be turned off are specified using the fc identifier.

The values for these fs and fc are obtained by adding the octal values from Table 11.5 together.

For example:

	Clear all delay bits and echo/full duplex
	0040000 + 0010000 + 0020000 + 0002000 + 0000400 + 0001000 +
	  0000010 = 0073410
	printtab entry = fc#0073410

	Set even and odd parity, enable automatic flow control.
	0100 + 0200 + 0001 = 0301	
	printtab entry = fs#0301
Remember these numbers are in octal (base 8). If you don't know how to do addition in base 8 obtain a calculator which supports octal. Most good scientific calculators should.
	Octal Value	Description

	0040000		form feed delay, 2 seconds
	0010000		carriage return delay, 0.08 second
	0020000		carriage return delay, 0.16 second
	0002000		tab delay
	0000400		newline delay
	0001000		newline delay, 0.1 second
	0000200		even parity
	0000100		odd parity
	0000040		pass all characters from filter to printer immediately
	0000020		translate linefeed into carriage return&linefeed
	0000010		echo, full duplex
	0000002		pass characters from printer to filter immediately
	0000001		automatic flow control

		Table 11.5. Flag Bits for a Serial Printer.

Local Bits


Local mode bits are used to configure the serial driver and use the same format as flag bits only with xc and xs instead. Most of these settings are intended for terminals. Those relevant for printers are listed in Table 11.6.
	Octal Value	Description

	000040		prevent serial driver from playing with codes
			  destined for printer
	040000		minimize flow control interference from line noise
	000001		tell the printer to backspace when it receives
			  an erase character

		Table 11.6. Local Mode Bits for a Serial Printer.

The BSD Print Commands


The lpq Command


lpq displays the list of jobs that are currently waiting to printed on a specified printer.
lpq [-Pprinter][-l][+[interval]][job#...][username]
With no parameters lpq will display a list of all print jobs on the default printer.
	Options	Purpose

	-P printer	display the queue of the specified printer
	-l		display using long format
	+[interval]	display the queue periodically until it empties,
			  interval specifies how many seconds it should sleep
	job#		display only those jobs with matching job numbers
	username	display only jobs belonging to the specified user

		Table 11.7. lpq Command Options.

The lpr Command


lpr is the command used to send information to be printed to the spooling area.
lpr [-Pprinter][-#copies] filenames


	Options		Purpose

	-Pprinter	specify printer to send information to,
			  by default this is lp
	-#copies	produce the number of copies indicated

		Table 11.8. lpr Command Options.

The lprm Command


lprm [-Pprinter][-][ job#...][username...]
lprm is used to remove jobs from the printer queue. It removes jobs matching printer, job# and username. The printer name defaults to lp and the job number defaults to the current job. Username defaults to the user invoking it.

Only the root user can remove someone else's print job.


The lpc Command


lpc is used to disable and enable the lpd daemon, disable and enable spooling and various other administrative duties on printers.
lpc [ command [ parameter.. ]]
If no commands are given lpc will enter interactive mode and present the lpc> prompt at which commands can be given.

Table 11.9 lists some of the commands that can be given to lpc. There are a number of other commands, refer to your manual page. These commands can be given at both the command line and from the lpc> prompt.

	Command			Purpose

	? [command]
	help [command]		provide short description of command
	abort [all | printer ]	terminate the daemon and then disable
				  printing for the specified printers.
	enable [all | printer ]	start spooling for the specified printers
	start  [all | printer ]	start printing for the listed printers
	stop  [all | printer ]	stop a spooling daemon and disable printing

		Table 11.9. lpc Command Options.
Exercise 11.2. Complete the software process for connecting your printer to your UNIX box.


Conclusions


The process of adding a printer to a UNIX machine involves two processes, hardware and software. The hardware steps involved in adding a printer are very similar to those involved in adding a terminal.

The UNIX print software is much more complex than that of a single-user operating system and is based on the concept of print spooling. The print services of BSD and SysV are completely different.


Review Questions


11.1. Describe the print software of your machine.

11.2. What is the purpose and relationship between the lp and lpr commands?

11.3. What is the purpose and relationship between lpd and lpsched?

11.4. What is the purpose of the /etc/printcap file?


Previous | Next

David Jones (author)
Chris Hanson (html 08/09/96)