1
$\begingroup$

So i just don't understand the relation between interrupts and Preemption in O.S?

For example in Multi-programming, do we need the support of Preemption or not? when a process needs I/O and sends an interrupt, do we use Preemption here to remove that process in order to get another process running, or no need for Preemption ?

$\endgroup$
1
$\begingroup$

For Multiprogramming you may or may not need Preemption. It depends upon the scheduling policy that is being used. For example First in First Out is non preemptive but shortest CPU burst is preemptive.

One more thing you are mixing blocking and preemption. When a process needs I/O it uses a system call. This system call results in a trap(software interrupt). Now this process is said to be blocked(waiting for I/O). Here the scheduler will definitely remove this process from running state and bring in a new process. Now please note that this whole thing does not invlove preemption.

Preemption means that the process is not blocked, yet the CPU is taken from it and given to some other process. Suppose a process is running and an interrupt comes which has no relation with this process. Now even though the process wants to run the interrupt must be served. Here we say that the process has been preempted.

Another example would be a list of processes being scheduled by shortest cpu burst algorithm. Suppose a process A having CPU burst 20 sec is running. Now suppose a new process arrives having a CPU burst of 10 seconds. Now A must be preempted to give chance to this second process.

Preemption is actually a good thing. It allows a CPU to serve more urgent things. Yet it may also cause some problems. A process may be preempted in the middle of updating a shared variable. This may lead to race condition.

Preemption can be simply avoided by disabling interrupts. But disabling interrupts is not a good thing at all. So nowadays all kernels used preemptive approach.

$\endgroup$
  • $\begingroup$ By way of clarification, MS-DOS implements software interrupts, but, being a single-tasking operating system, does not do preemption. $\endgroup$ – David A. Gray Dec 2 '17 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.