18

Mark wrote a comment for me

I don't know offhand how to make cups not spool, that is, how to make the lpr command only exit after the printer driver has run.

What does "spool" for printing mean?

Google says it is a verb meaning "send (data that is intended for printing or processing on a peripheral device) to an intermediate store." What is the intermediate store that printing spool represents, for example, when printing by lpr command

Mark seems to relate the meaning of spool with blocking. But I can't figure that out by looking at the definition given by Google.

Thanks.

12

A print spool is effectively a buffer, managed per job, with a program (the spooler) responsible for receiving jobs from submitting programs and feeding them to one or more printers. The point of a spool is to handle communication between two systems with different speeds, and to control access to shared devices. The former means programs can submit print jobs as fast as they want, and those jobs are dealt with as fast (or slowly) as printers can handle. The latter (as pointed out by RonJohn) ensures that jobs are handled coherently: thus when printing, jobs aren’t mixed up.

Networked printers provide their own spools, and print servers (CUPS, lpd etc.) also implement spools. Most print systems also handle access control, quotas, banners, print options etc. Spools are used in other contexts; for example, tape-based backup servers now spool backup data from networked hosts on a fast disk-based storage system, so that they can then feed modern tape drives at the tremendous speeds they need to avoid tape shoe-shine.

In the context of the comment, the relevance of a spool is that it decorrelates the print job submission from its fulfillment. Not spooling would mean that the submission would only complete with the print job, and thus your lpr command would only complete once the job completed. Removing the spool on your computer might not have the desired result though since the printer itself could spool too!

  • 1
    Which part of the meaning of "spool" make it not applicable to the IO buffer of Linux kernel? – Tim Sep 24 '18 at 16:19
  • 3
    The mail system is often using a mail spool under /var/spool/mail or similar location. This is also a "buffer" to allow for close to asynchronous sending of mail messages. The mail message is spooled/queued and the mail client does not have to wait for the mail to actually leave the system. Very much like a printing job. – Kusalananda Sep 24 '18 at 16:37
  • 1
    @Tim it’s not really a question of it being applicable or not, it’s just not called a spool. Buffers generally do result in the operations feeding into the buffer being nonblocking: write completes as soon as the data is written into whatever buffer is used (in Linux, the page cache), not once the data is really at its destination. read isn’t necessarily non-blocking either, and can return less data than was requested. – Stephen Kitt Sep 24 '18 at 20:10
  • 1
    Note also that -- in addition to handling "communication between two systems with different speeds" -- spools serialize access to those slower devices. (You can imagine how bad it would be for multiple jobs to all write to the printer or modem at the same time...) – RonJohn Sep 25 '18 at 8:39
  • 1
    Print spools are typically stored on disk, wherever the print server is hosted. When I say printers can also have their own spool, this is normally the case for “networked” printers (which are connected to a network, rather than to a specific computer); they host their own print server(s) and have to manage multiple incoming jobs (which they do by having their own spool). When a printer has its own spool, it can accept print jobs much faster than they can be printed, so even if lpr waited for the printer to finish accepting the job, there would still be lag before it was fully processed. – Stephen Kitt Oct 5 '18 at 7:35
36

In a nutshell, a spooler consists of:

  • a background program
  • a directory per printer
  • a file per print job

In your case, the foreground program (lpr) sends its print jobs to cups, which stores it and then uses serial, parallel, USB, network, ... communication to actually start the printing process.

So that's why nowadays even when the printer runs out of paper you can still continue using your computer, whereas back when I was a kid on CP/M, the whole computer locked up until you added more paper...

Why is it called "spooling"?

Because in those times, large computers used tape to store these kind of files as disks were too expensive, so when you were working inside the data center, the first thing you would hear was the tapes starting to spin up¹ and only after a second or 3-4 the printer would start printing (if you were lucky). ;-)

Note ¹: A "spool" is a noun meaning "a cylindrical device on which magnetic tape can be wound", therefore "spooling" is the cylindrical device spinning up and winding up tape...

  • 5
    More directly, "spool" is a noun meaning "a cylindrical device on which magnetic tape can be wound" – OrangeDog Sep 25 '18 at 9:19
  • 1
    @OrangeDog: incorporated into answer, thanks! :-) – Fabby Sep 25 '18 at 13:07
  • 2
    +1 Never knew where the term "spool" came from. – Joe Sep 29 '18 at 0:34
  • @Joe Same reason kids nowadays don't know what the save button actually means as they've never seen a Diskette / Floppy / Stiffy / ... >:-) – Fabby Aug 3 at 21:31
5

First, let’s begin with the meaning of the term “spooling”: sometimes the size of a document is larger than the printer’s memory, so “printer spooling” allows the sending of multiple documents to a printer and putting all theses documents in a queue.

Now, under Unix there are two printing systems:

  1. The BSD spooling system uses lpd daemon to schedule the print jobs.
  2. The SVR4 spooling system uses lpsched as the scheduler.

Jeff Lessem’s USAIL: Unix system administration independent learning has a section on Printing under Unix which provides a good overview of both the BSD and SVR4 systems:

The BSD spooling system

extends well to large, heterogeneous networks allowing many computers to share printers.

Under the BSD spooling system, access to printers is controlled by lpd daemon and the lpr program. lpr is the only program on a BSD system that can queue files for printing.

lpr accepts data to be printed, puts it in a spooling directory, and notifies the lpd daemon. For each print job, lpr creates two files, a control file (cfxxx) and a data file (dfxxx) in the spool directory, xxx indicating a unique job-id. The control file contains the information for handling the print job, including the identity of the owner. The data file contains the actual data to be printed.

The lpd daemon checks the /etc/printcap file to identify the destination printer. If the destination printer is a local device, lpd makes sure a copy of the lpd daemon is running on that print queue. Otherwise lpd opens a connection to the remote host to which the printer is connected and transfers both the control and data file to it.

Print jobs are scheduled by lpd on a First-In, First-Out (FIFO) basis. However, the system administrator may use the lpc command to alter the priority of the jobs in the print queue.

SVR4 spooling system is used by Solaris and HP-UX. It offers more control and flexibility but was not designed for network printing and is more complicated to set up.

Under SVR4 spooling system, the lp command accepts the data to be printed, makes a copy of it in the spool directory associated with the destination. The destination consists of a printer name and an optional specification of a class to which the printer belongs. When the specified printer is busy the job is sent to another printer in the same class. The spool directory is normally /var/spool/lp/request/printer-name and the print file is given a unique name to identify both the job and the user.

Access to the printer is controlled by lpsched daemon. It picks up the jobs from the spool directory and sends them to appropriate destination when it becomes available. lpsched also keeps a log, usually in /usr/spool/lp/log. The log file would indicate any error in processing the print jobs, as well as the user-name,

See also: Printers and printer spooler – lp, lpstat and cancel commands | Tips & Tricks for IT's Blog

4

Never forget that SPOOL is an acronym for Simultaneous Peripheral Operations On Line. Since the early (but not earliest) days of computing, processors generated results faster than the printers could print them. Without spooling, the processor could not finish a "print job" until the printing itself was finished. This often resulted in an idle processor, waiting around for the printer.

A great leap forward in spooling came during the American space program. The computers were producing results too slowly, so a new spooling system was written just for NASA (although it and its successors gained in popularity until all IBM systems had them). It was called the Houston Automatic Spooling Program, making HASP the first nested acronym.

A good analogy to spooling is a thread factory -- thread is spun at a fast rate, and stored -- where else -- onto a spool. Then the spool of thread is eventually put on a sewing or other machine, that runs at a much slower rate, where it is used to create a finished product.

  • 17
    Note that that derivation of "spool" is widely considered to be a backronym, and "PDQ" definitely is. – chrylis -on strike- Sep 24 '18 at 19:34
  • 6
    It's obviously a backronym constructed after the fact. It's becoming a fad to spread such rumours. A lot of them are listed here, maybe it's time to add "spool" to it! – pipe Sep 24 '18 at 19:52
  • 4
    @Jennifer While IBM certainly had a program called SPOOL, it's widely conjectured, as in the Jargon File link above, that they either chose that name as a sort of pun, or derived it from an existing term. Either way, it probably refers to loading the jobs onto a spool of tape and then playing them back. In modern usage, it refers neither to an obsolete IBM product nor a spool of tape, so the whole debate is rather academic and tangential to the question of what it means today. – IMSoP Sep 25 '18 at 15:05
  • 3
    @Jennifer Well, I'm not wrong that it's widely conjectured, even if people are wrong to conjecture it. And even if it's true that IBM invented the term, why did they choose those words? Did they write the name out longhand and then say "oh, that's a coincidence, it spells an English word" - or is it more likely they were looking for a term that seemed appropriate for the functionality, and thought that "spooling the jobs onto the tape" was a good image? – IMSoP Sep 25 '18 at 15:30
  • 4
    This post would benefit greatly from citations, in particular for it's etymological claims. – TemporalWolf Sep 25 '18 at 17:50
3

Spooling is a fairly old school term. Nowadays you'll see "Print Queue" used more often.

To Queue is a British saying to "wait in line". So print jobs are "queued", ie waiting in line to print.

After a job has finished spooling (there can be long "thinking" times between print lines), then it is printed, generally in a FIFO basis but Print Job priority can override it.

Print spools and queues can be paused for Operators to change paper. The can also be restarted if some pages were damaged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.