In this video, we will understand what is Printer Spooler problem in Operating systems.
Printer Spooler problem is a process synchronization issue. It arises when a single printer is shared among multiple processes (users). Spooler keeps a record of the files to be printed by the printer. Whenever the printer completes a printing task, the spooler assigns the next task to the printer (if any).
To keep the file in a printer, each process needs to execute the following code:
Load Ri, m[i]
Store SD[R], “File”
INCR Ri
STORE m[i], Ri
Case I- Single Process
If process P1 wants to print file F1, P1 executes the spooler code. Initially, variable i points to the first empty location (0) in the spooler directory. The contents of memory location i will be saved in register R1 (= 0). File F1 will be stored in the spooler directory location R1 (= 0). R1 will be incremented to value 1.
The value of memory location i will be updated to new value of R1. No printer spooler problem in this scenario.
Case II- Two Process
If there are 2 process P2 and P3 such that P2 wants to store a file F2 and P3 wants to store a file F3 in spooler directory for printing. If P2 arrived first in the system, it will start executing the spooler code. The contents of memory location i will be saved in register R2 (= 1). File F2 will be stored in the spooler directory location R2 (= 1). R2 will be incremented to value 2.
Suppose before executing the last instruction, P3 arrives in the system. At this time, value of i is 1 because the value of i was not incremented by P2. The contents of memory location i will be saved in register R3 (= 1).
File F3 will be stored in the spooler directory location R3 (= 1). R3 will be incremented to value 2. The value of memory location i will be updated to new value of R3 (=2). P3 has completed its execution of the spooler code. So the control will again be given back to P2 to complete its last spooler code instruction. The value of memory location i will be updated to new value of R2 (=2).
Print spooler problem:
https://www.geeksforgeeks.org/printer-spooler-problem/