Related Content: CS604 - VU Lectures, Handouts, PPT Slides, Assignments, Quizzes, Papers & Books of Operating Systems
The objective of multiprogramming is to have some process running at all times, in order
to maximize CPU utilization. In a uniprocessor system, only one process may run at a
time; any other processes much wait until the CPU is free and can be rescheduled.
In multiprogramming, a process is executed until it must wait, typically for the
completion of some I/O request. In a simple computer system, the CPU would then sit
idle; all this waiting time is wasted. Multiprogramming entails productive usage of this
time. When one process has to wait, the OS takes the CPU away from that process and
gives the CPU to another process. Almost all computer resources are scheduled before
use.
As shown in Figure 14.1, process execution consists of a cycle of CPU execution and I/O
wait. Processes alternates between these two states. Process execution begins with a CPU
burst. An I/O burst follows that, and so on. Eventually, the last CPU burst will end with
a system request to terminate execution, rather than with another I/O burst.
An I/O bound program would typically have many very short CPU bursts. A CPUbound
program might have a few very long CPU bursts. This distribution can help us
select an appropriate CPU-scheduling algorithm. Figure 14.2 shows results on an
empirical study regarding the CPU bursts of processes. The study shows that most of the
processes have short CPU bursts of 2-3 milliseconds.
Whenever the CPU becomes idle, the operating system must select one of the processes
in the ready queue to be executed. The short-term scheduler (i.e., the CPU scheduler)
selects a process to give it the CPU. It selects from among the processes in memory that
are ready to execute, and invokes the dispatcher to have the CPU allocated to the selected
process.
A ready queue can be implemented as a FIFO queue, a tree, or simply an unordered
linked list. The records (nodes) in the ready queue are generally the process control
blocks (PCBs) of processes.
The dispatcher is a kernel module that takes control of the CPU from the current process and gives it to the process selected by the short-term scheduler. This function involves:
The time it takes for the dispatcher to stop one process and start another running is known as the dispatch latency.
CPU scheduling can take place under the following circumstances:
In 1 and 4, there is no choice in terms of scheduling; a new process must be selected
for execution. There is a choice in case of 2 and 3. When scheduling takes place only
under 1 and 4, we say, scheduling is non-preemptive; otherwise the scheduling scheme
is preemptive. Under non-preemptive scheduling once the CPU has been allocated to a
process the process keeps the CPU until either it switches to the waiting state, finishes its
CPU burst, or terminates. This scheduling method does not require any special hardware
needed for preemptive scheduling.
Preemptive scheduling incurs a cost. Consider the case of two processes sharing data.
One may be in the midst of updating the data when it is preempted and the second
process is run. The second process may try to read the data, which are currently in an
inconsistent state. New mechanisms are needed to coordinate access to shared data. We
discuss this topic in Chapter 7 of the textbook.
The scheduling criteria include:
We will now discuss some of the commonly used short-term scheduling algorithms.
Some of these algorithms are suited well for batch systems and others for time-sharing
systems. Here are the algorithms we will discuss:
The process that requests the CPU first (i.e., enters the ready queue first) is allocated the
CPU first. The implementation of an FCFS policy is managed with a FIFO queue. When
a process enters the ready queue, its PCB is linked onto the tail of the queue. When CPU
is free, it is allocated to the process at the head of the queue. The running process is
removed from the queue. The average waiting time under FCFS policy is not minimal
and may vary substantially if the process CPU-burst times vary greatly. FCFS is a nonpreemptive
scheduling algorithm.
We use the following system state to demonstrate the working of this algorithm. For
simplicity, we assume that processes are in the ready queue at time 0.
Suppose that processes arrive into the system in the order: P1, P2, P3. Processes are served in the order: P1, P2, P3.The Gantt chart for the schedule is shown in Figure 14.3.
Here are the waiting times for the three processes and the average waiting time per process.
Suppose that processes arrive in the order: P2, P3, P1. The Gantt chart for the schedule is shown in Figure 14.4:
Here are the waiting times for the three processes and the average waiting time per process.
When FCFS scheduling algorithm is used, the convoy effect occurs when short
processes wait behind a long process to use the CPU and enter the ready queue in a
convoy after completing their I/O. This results in lower CPU and device utilization than
might be possible if shorter processes were allowed to go first.
In the next lecture, we will discuss more scheduling algorithms.