LPRng Reference Manual: 3 May 2004 (For LPRng-3.8.27)
Prev | Chapter 4. Print Spooling Tutorial | Next

# 4.7. Controlling the Print Queue

The lpc command is used to examine and control the print server operation. The `lpc status` command displays the administrative status of a print queue. The lpd program caches status and job information in order to improve performance. The `lpc flush` command will flush the cached information and cause the server to regenerate it. The `lpc enable` and `lpc disable` commands enable or disable spooling to the print queue, and the `lpc stop` and `lpc start` commands stop and start printing (or transfers) of jobs in the print queue.

Let's look at the status displayed when we use these commands:

        h4: {120} % lpc status
         Printer  Printing Spooling Jobs Server Subserver Redirect Status/(Debug)
        lp@h4      enabled  enabled    0   none    none
        h4: {121} % lpc status all
         Printer  Printing Spooling Jobs Server Subserver Redirect Status/(Debug)
        lp@h4      enabled  enabled    0    none    none
        lp2@h4     enabled  enabled    0    none    none
        h4: {122} % lpc
        lpc>status
         Printer  Printing Spooling Jobs Server Subserver Redirect Status/(Debug)
        lp@h4      enabled  enabled    0    none    none
        lpc>status all
         Printer  Printing Spooling Jobs Server Subserver Redirect Status/(Debug)
        lp@h4      enabled  enabled    0    none    none
        lp2@h4     enabled  enabled    0    none    none
        lpc>quit

The lpc command can be used in command line or interactive mode as shown above. When used with no parameters it will run in interactive mode, reading one or more commands from its standard input (STDIN). The `lpc status` command shows the administrative status of the select print queue. The all queue name selects all print queues for display. As shown in the above example, both print queues have printing and spooling enabled and there are no jobs in the print queue. The Server and Subserver information shows if there is a process which is printing jobs, and its helper process that does the actual communication with the printer.

It might be puzzling at first why LPRng uses two processes for this operation, but the reason is very simple. Many operating system implementations have memory leaks that cause the actual process size to grow as it runs. This is especially true if a large number of databases such as the password, Domain Name Server, or other system database is consulted frequently with different queries. Since this is usually done quite a lot by the process which deals with the actual printing, the printing process would soon grow very large and then die when it could no longer obtain more memory. The Server process will fork or create a child process Subserver process that is responsible for the printing of a single job. When the job printing has been completed, the Subserver process will exit and the Server process will then create another child until there are no more jobs to be printed. The Redirect and Debug fields will be discussed in later sections.

Now let's use the basic spool queue control commands:

        h4: {123} % lpc disable
        Printer: lp@h4
        lp@h4.private: disabled
        h4: {124} % lpq
        Printer: lp@h4  (spooling disabled)
         Queue: no printable jobs in queue
        h4: {125} % lpc enable
        Printer: lp@h4
        lp@h4.private: enabled
        h4: {126} % lpq
        Printer: lp@h4
         Queue: no printable jobs in queue
        h4: {127} % lpc stop
        Printer: lp@h4
        lp@h4.private: stopped
        h4: {128} % lpq
        Printer: lp@h4  (printing disabled)
         Queue: no printable jobs in queue
        h4: {129} % lpc start
        Printer: lp@h4
        lp@h4.private: started
        h4: {130} % lpq
        Printer: lp@h4
         Queue: no printable jobs in queue

As we can see, the lpc command also reports on the status of the print queue. Let's see what happens when we print to a stopped queue:

        h4: {131} % lpc stop
        Printer: lp@h4
        lp@h4.private: stopped
        h4: {132} % lpr /tmp/hi
        h4: {133} % lpr /tmp/hi /tmp/there
        h4: {134} % lpq
        Printer: lp@h4  (printing disabled)
         Queue: 2 printable jobs
         Server: no server active
         Rank   Owner/ID               Class Job Files            Size Time
        1      papowell@h4+17920         A 17920 /tmp/hi             3 18:14:22
        2      papowell@h4+17922         A 17922 /tmp/hi,/tmp/there  9 18:14:30
        h4: {135} % lpc status
         Printer  Printing Spooling Jobs  Server Subserver Redirect Status/(Debug)
        lp@h4     disabled  enabled    2    none    none

The lpc status shows that we have two jobs spooled. The Rank field shows the order, the `Owner/ID` shows the unique job ID that is assigned to the job and the Class field is the job class (this may be changed with the `lpr -C class` option). The Job field shows the job number assigned to this job in this particular spool queue. While the ID value never changes as a job moves through the LPRng system, the job number is specific to a particular spool queue and may change if a job is forwarded to another spool queue that has a job with the same job number. The Size field is the total number of printable bytes in the job, and the Time field shows the timestamp associated with the job.

Now let's start the print queue and watch what happens.

        h4: {136} % lpc start
        Printer: lp@h4
        lp@h4.private: started
        h4: {137} % lpq
        Printer: lp@h4
         Queue: 2 printable jobs
         Server: pid 17928 active
         Unspooler: pid 17929 active
         Status: opening device '/tmp/lp' at 18:14:43.921
         Rank   Owner/ID             Class Job Files            Size Time
        active papowell@h4+17920       A 17920 /tmp/hi             3 18:14:22
        2      papowell@h4+17922       A 17922 /tmp/hi,/tmp/there  9 18:14:30
        h4: {138} % lpq -ll
        Printer: lp@h4
         Queue: 2 printable jobs
         Server: pid 17928 active
         Unspooler: pid 17929 active
         Status: printing job 'papowell@h4+17920' at 18:14:43.921
         Status: no banner at 18:14:43.921
         Status: printing data file 'dfA017920h4.private', size 57 at 18:14:43.922
         Rank   Owner/ID             Class Job Files            Size Time
        active papowell@h4+17920       A 17920 /tmp/hi             3 18:14:22
        2      papowell@h4+17922       A 17922 /tmp/hi,/tmp/there  9 18:14:30

The Rank value of the first job has been changed to active and there is new Status information. If we use `lpq -ll` we can see the times that the various print operations are carried out, and details of their success or failure.

We can also use the lpc command to see the status of a particular job. We can select jobs by the user name, the ID, or the job number. For example:

        h4: {139} % lpc stop
        Printer: lp@h4
        lp@h4.private: stopped
        h4: {140} % echo hi |lpr
        h4: {141} % echo there | lpr
        h4: {142} % echo test |lpr
        h4: {143} % lpq
        Printer: lp@h4  (printing disabled)
         Queue: 3 printable jobs
         Server: no server active
         Status: job 'papowell@h4+17922' removed at 18:15:13.981
         Rank   Owner/ID            Class Job Files           Size Time
        1      papowell@h4+17959      A 17959 (stdin)            3 18:23:24
        2      papowell@h4+17962      A 17962 (stdin)            6 18:23:30
        3      papowell@h4+17970      A 17970 (stdin)            5 18:23:35
        h4: {144} % lpq 17970
        Printer: lp@h4  (printing disabled)
         Queue: 3 printable jobs
         Server: no server active
         Status: job 'papowell@h4+17922' removed at 18:15:13.981
         Rank   Owner/ID            Class Job Files           Size Time
        3      papowell@h4+17970      A 17970 (stdin)            5 18:23:35
        h4: {145} % lpq papowell
        Printer: lp@h4  (printing disabled)
         Queue: 3 printable jobs
         Server: no server active
         Status: job 'papowell@h4+17922' removed at 18:15:13.981
         Rank   Owner/ID            Class Job Files           Size Time
        1      papowell@h4+17959      A 17959 (stdin)            3 18:23:24
        2      papowell@h4+17962      A 17962 (stdin)            6 18:23:30
        3      papowell@h4+17970      A 17970 (stdin)            5 18:23:35
        h4: {146} % lpq -s 17970
        lp@h4  1 jobs
        h4: {147} % lpq -s papowell
        lp@h4  3 jobs
        h4: {148} % lpq -s nobody
        lp@h4  0 jobs

We use `lpq -Pqueuename` to select a specific print queue and `lpq -a` or `lpq -Pall` to select all queues:

        h4: {149} % lpc -a stop
        Printer: lp@h4
        lp@h4.private: stopped
        Printer: lp2@h4
        lp2@h4.private: stopped
        h4: {150} % lpc -Pall start
        Printer: lp@h4
        lp@h4.private: started
        Printer: lp2@h4
        lp2@h4.private: started

You can use the lpc command in interactive mode:

        h4: {151} % lpc
        lpc>status
         Printer  Printing Spooling Jobs  Server Subserver Redirect Status/(Debug)
        lp@h4      enabled  enabled    3    17990   17993
        lpc>status all
         Printer  Printing Spooling Jobs  Server Subserver Redirect Status/(Debug)
        lp@h4      enabled  enabled    3    17990   17993
        lp2@h4     enabled  enabled    3    none    none
        lpc>stop lp
        Printer: lp@h4
        lp@h4.private: stopped
        lpc>start lp
        Printer: lp@h4
        lp@h4.private: started
        lpc>quit

The `lpc topq` command can be used to put a job (or jobs) at the head of the spool queue. This command is very useful when some job requires priority service. You can select the job by using the job number or the job ID.

        h4: {152} % lpc topq lp 17970
        Printer: lp@h4
        lp: selected 'papowell@h4+17970'
        lp@h4.private: started
        h4: {153} % lpq
        Printer: lp@h4
         Queue: 3 printable jobs
         Server: pid 17999 active
         Rank   Owner/ID          Class Job Files      Size Time
        active papowell@h4+17970    A 17970 (stdin)      5 18:23:35
        1      papowell@h4+17959    A 17959 (stdin)      3 18:23:24
        2      papowell@h4+17962    A 17962 (stdin)      6 18:23:30

Prev | Home | Next
Selecting the Print Queue | Up | Job Removal