Microsoft Interview Question
Software Engineer in TestsTeam: Windows Hyper-V
Country: United States
Interview Type: Phone Interview
The jobs in the printer are basically kept in a queue and if only one instance is there and several jobs to be printed are there then the printer prints the jobs on a first come first serve basis.
But when two or more instances of the word are running and simultaneous instructions are provided to print the job to the printer then the priority to the jobs should be given according to the size of the job. Suppose the size of one job is 100 kb and size of another job is 50 kb then the priority to first job should be given. Thus the printer driver could be designed on the basis of priority queue. To ensure it more we can use a counting semaphore where the less-size job holds the resources that is the printer driver until it is completely printed after which the resource becomes available to the next job for printing.
yeah but why to give priority to the lengthier job? The average finish time will be more if we give higher priority to lengthier job. What am i missing?
Assumptions:
Printer has unlimited memory
We have two components:
1. Client driver on the machine
2. The service listening on the printer
On receiving a request to print, the client driver on the machine sends a notification to the printer about a print job. The printer stores the request in a FIFO queue. The printer has a different thread which dequeues from the queue and processes that job. While processing, it calls back the client driver and downloads the entire document to be printed.
This is very high level but you can decompose these components and decide on the different messages and contents of the message.
Plus, if the assumption of unlimited memory is untrue, there needs to be a secondary memory which is larger. Optimizations will be required to print multiple copies of the same doc in this case in order to avoid downloading the doc multiple times.
There can be two possible solutions to this problem
- NaMo June 30, 2013I ) Use Print Spooler of OS
II ) Design specific program to handle prints
if we follow option (I) then life is simple, just put every print request we get to spooler and OS will mange by itself ( actually its a solution to producer-consumer problem )
if we follow option (II) then we would have to design priority scheduler as mentioned by @vgeek on any basis we like whether size, time of arrival or even user can be asked for priority if two print commands are given simultaneously. This would require us to code manually the work of spooler.