Printer Spooler Problem

Printer spooler problem is a standard problem of process synchronization. A printer spooler is a small application that manages the paper printing jobs sent from a computer to a printer or print server. It enables storing multiple print jobs within a print queue or a buffer where it’s retrieved by the printer or print server.

Let’s explain with example

Suppose we have a network and only one printer is there in the network. All users in the network are using the same printer.

As Printer is very slow speed device as compare to Processor. So for printing there is a spooler directory which keeps the entire file for printing through Print Spooler program.

What is a Printer Spooler program?

It is software which is responsible to manage All printing files exist in printing spooler directory. Print spooler program execute one by one all files on printer from the printing spooler directory.

How to add files of printing in the printing spooler directory?

If any process wants to print a document then he will execute the four line code to add document in spooler directory


Let Suppose

“IN=0” is the shared variable which tells the position of incoming document in the printing spooler directory.

R1 is the Register; SD is the directory, File1.doc, File2.doc, File3.doc, File4.doc, and File5.doc are files.


LOAD R1, M[IN] // Load the IN value in register R1 so R1=0
STORE SD[R1], “File1.doc” // save File1.doc in SD position 0
INCR R1 // R1=R1+1= 0+1=1
STORE M[IN], R1 // Store R1 value in IN shared variable so IN=1

CASE: 01

When there is no interrupt is occur during the execution of above four lines then printer spooler program works properly.  Let suppose there are two processes. Process P1 having register R1 and File1.doc file. In the same way, P2 having register R2 and File2.doc file.

But the case is when P1 complete execution of 4 line codes and then P2 will execute. In this way printer spooler program works perfect as given below in diagram. There will be no problem

printer spooler problem normal working

CASE: 02

Let suppose, P1 and P2 are two processes.

P1 having R1 register and File1.doc file. In the same way, P2 having register R2 and File2.doc file. Both processes are sharing the IN variable and running parallel on uniprocessor.

printer spooler problem in working


If P1 execute the instructions 1, 2, 3 and an interrupt is occur then OS save the record of P1 in its PCB and CPU preempt to P2.

PCB Till now of P1 is,

  • first instruction Result is : R1=0
  • Second instruction Result is :  File1.doc is in Zero position of Spooler Directory (SD)
  • Third instruction Result is : R1=1

Note:  IN=0

(After the execution of 4th instruction, the value of IN will store in R1. But here still 4th is pending due to interrupt just after the 3rd instruction. So, IN=0)

When P2 execute the above four lines then result till now is 

  • first instruction Result is: R2=0
  • Second instruction Result is: File2.doc is in Zero position of Spooler Directory (SD)
  • Third instruction Result is: R2=1
  • Fourth instruction Result is: IN=1

After P2 CPU preempt back to P1 and execute the 4th instruction

  • Result of Fourth instruction: IN=1

CONCLUSION: File1.doc is replaced with File2.doc at position 1 of Process P2. File1 is lost because processes are not synchronized. In simple words we can say, when shared variables are used in printer spooler program then data may overwrite in some cases. that’s why, process synchronization is important. Solutions of such problems through are semaphore, mutex, peterson solution etc.


If there are three files already in main memory then the value of IN=3 and P1, P2 executing parallel then Find the results as given above in case 1 and 2?

If It Is Useful, Help Other’s By Sharing…

Help Other’s By Sharing…

Contact Us

Burewala, Vehari, Punjab, Pakistan


Pin It on Pinterest