What is the exact definition of 'process preemption'?

LordFenerSSJ picture LordFenerSSJ · Apr 30, 2016 · Viewed 8.1k times · Source

Wikipedia says:

In computing, preemption is the act of temporarily interrupting a task being carried out by a computer system, without requiring its cooperation, and with the intention of resuming the task at a later time.

Other sources say:

[...] preemption means forcefully taking away of the processor from one process and allocating it to another process. [Operating Systems (Self Edition 1.1), Sibsankar Haldar]

Preemption of a program occurs when an interrupt arises during its execution and the scheduler selects some other programs for execution. [Operating Systems: a Concept-based Approach, 2E, D. M. Dhamdhere]

So, what I understood is that we have process preemption if the process is interrupted (by a hardware interrupt, i.e. I/O interrupt or timer interrupt) and the scheduler, invoked after handling the interrupt, selects another process to run (according to the CPU scheduling algorithm). If the scheduler selects the interrupted process we have no process preemption (interrupts do not necessarily cause preemption).

But I found many other sources that define preemption in the following way:

Preemption is the forced deallocation of the CPU from a program. [Operating Systems: a Concept-based Approach, 2E, D. M. Dhamdhere]

You can see that the same book reports two different definitions of preemption. In the latter it is not mentioned that the CPU must be allocated to another process. According to this definition, preemption is just another name for 'interruption'. When a hardware interrupt arises, the process is interrupted (it switches from "Running" to "Ready" state) or preempted.

So my question is: which of the two definitions is correct? I'm quite confused.

Answer

user3344003 picture user3344003 · Apr 30, 2016

The Wikipedia definition is pretty bad.The others are not so good. However, they are all saying essentially the same think.

Preemption is simply one of the means by which the operating system changes the process executing on a CPU.

Such a change can occur either through by the executing process voluntarily yielding the CPU or by the operating system preempting the executing process.

The mechanism for switching processes (context switch) is identical in both methods. The only difference is how the context switch is triggered.

A process can voluntarily yield the CPU when it no longer can execute. E.g. after doing I/O to disk (which will take a long time to complete). Some systems only support voluntary yielding (cooperative multitasking).

If a process is compute-bound, it would hog the CPU, no allowing other processes to execute. Most operating systems use a timer interrupt. If the interrupt handler finds that the current process has executed for at least a specified period of time and there are other processes that can execute the OS will switch processes.

Preemption is then a process (or thread) [context] switch on a CPU that is triggered by the operating system rather than by the process (or thread) itself.