CPU Scheduling:
The CPU scheduling serves as a basis for multi programmed OS.
The idea of multiprogramming is simple; if a process or job is waiting for an
IO request then the CPU switches from that job to another job. So, the CPU is
always kept busy in multiprogramming as it has something to execute at all
times. However, in case of a simple computer system, CPU often sits idle until
the IO request is granted. Thus, by switching the CPU among processes, an OS
can increase productivity and utilization of a computer system.
Scheduling is a fundamental operating system function.
Managing the CPU resources is commonly termed as Scheduling. All of the
computer resources are scheduled before their use. The CPU is one of the
primary resources amongst all resources. Hence, the CPU is also scheduled
before use.
An allocation of the CPU to processes is determined using
various CPU scheduling algorithms. There are two types of CPU scheduling
algorithms:
1.
Non-
preemptive scheduling algorithms
2.
Preemptive
scheduling algorithms
A CPU has to make scheduling decisions under the following
circumstances when a process switches from:
1.
running
to waiting state
2.
running
to ready state
3.
waiting
to ready state or;
4.
when
a process terminates.
In non-preemptive scheduling, once the CPU is assigned to a
process, the processor do not release until the completion of that process. The
CPU will be assigned to some other job only after the previous job has
finished. Non – preemptive scheduling takes place for circumstances 1 and 4 mentioned above. MS
Windows 3.1 and Apple’s Mac uses this method of CPU scheduling. It is
relatively very simple to implement.
However, in preemptive scheduling, the CPU can release the
processes even in the middle of its execution. Consider an example where the
CPU is executing process P1. While it is executing, the CPU receives a request
signal from process P2. Then, in this
case an OS compares the priorities of processes P1 and P2. If the priority of
P1 > P2, then the CPU continues with the execution of process P1. Otherwise,
CPU preempts process P1 and assigns it to process P2. Preemptive scheduling
takes place for circumstances 2 and 3 mentioned above.
The preemptive scheduling techniques are used to ensure quick
response to high priority processes. But, they incur a cost. It is more
responsive but it imposes higher overhead because it requires a process
switching.
Differences between Preemptive and Non-Preemptive Scheduling:
Preemptive
Scheduling |
Non-Preemptive
Scheduling |
It
allows a process to be interrupted in the midst of its execution by taking
the CPU and allocating it to another process. |
It
ensures that process gives control of the CPU only when it finishes with its
current CPU burst. |
It
incurs cost associated with access to shared data. |
Does
not incur cost. |
It
also affects design of OS kernel. |
It
does not affect design of OS kernel. |
More
complex to implement. |
Simple
to implement but, very inefficient. |
Ex:
Round Robin (RR) method. |
Ex:
First Come First Serve (FCFS) method. |
No comments:
Post a Comment