The preemptive is clear: the process is executed, then he needs a printer. Another process starts to run. He suddenly also needed a printer. And the first one has not finished printing yet. The second one is queuing up to the printer.

And in non-preemptive queue from where? The process is executed, well, he needed a printer, it will print, another process will not start running while it is printing.

UPD: I heard that with non-preemptive multitasking, the process can yield to the processor when it has finished execution or when it needs a resource that is currently unavailable. But how can it be unavailable? Will consider from the first process. That took the first process in the current session processor. It took him a device. How can it be unavailable? Who is employed? The process is the first. So he will print without giving the processor to anyone. Then it ended, the second process came ... and for him the same reasoning is valid as for the first one, isn't it?

  • With non-displacing multitasking, the process is not forcibly interrupted during the execution of calculated tasks. When a process requires input / output (for example, a printer), the process will be switched by the OS since the current process will wait for the response from the external device (printer) and just at this moment another task will also want to print - Mike
  • @Mike, apparently I do not understand this well, and did not fully disclose my understanding of the question. Therefore updated the question. Tell me please, what is wrong? - Alexander Elizarov
  • You have an abstract question, i.e. “How should all this work in principle?” or are you still talking about some concrete implementations? - avp

1 answer 1

With non-displacing multitasking, the process is not forcibly interrupted during the execution of calculated tasks. When a process requires input / output (for example, a printer), the process will be switched by the OS since the current process will wait for the response from the external device (printer) and just at this moment another task will also want to print.

In general, I / O works independently of the processor. The processor is not busy for example printing each individual character. It sends a block of data to the printer (possibly several pages in size) and the printer prints. At this time, the CPU is free and can do other work. Either the calling process uses this time on its own, or the OS uses it to perform another process.

And all the I / O works in a similar way. The process wanted to read from the disk. The OS sends a read command to the disk and configures the DMA (Direct Memory Access Device) to transfer data from the disk to the desired area of ​​RAM. After that, the processor is again completely free until the disk finishes the operation. And usually the process that decided to receive data from the disk has absolutely nothing to do while the data is being prepared, therefore the OS switches the task and lets the other process work. Another process may also want to turn to the same disk and then it will be queued because The disk and DMA channel are already occupied at this time.