11226experiment No 5-Scheduling
11226experiment No 5-Scheduling
PART A
(PART A : TO BE REFFERED BY STUDENTS)
A.1 Aim:
Process Management: Scheduling
a. Write a program to demonstrate the concept of non-preemptive scheduling algorithms.
b. Write a program to demonstrate the concept of preemptive scheduling algorithms
A-2 Prerequisite
Knowledge about C/C++ and Java Programming.
A.3 OutCome
After successful completion students will able to Interpret and examine different process
scheduling algorithms.
A.4 Theory:
CPU scheduling deals with the problem of deciding which of the processes in the ready queue is
to be allocated the CPU. There are many different CPU scheduling algorithms.
2. SHORTEST-JOB-FIRST SCHEDULING :
A different approach to CPU scheduling is the shortest-job-first (SJF) scheduling
algorithm. This algorithm associates with each process the length of the process’s next
CPU burst. When the CPU is available, it is assigned to the process that has the smallest
next CPU burst. If the next CPU bursts of two processes are the same, FCFS scheduling
is used to break the tie. As an example of SJF scheduling, consider the following set of
processes, with the length of the CPU burst given in milliseconds:
The waiting time is 3 milliseconds for process P1, 16 milliseconds for process P2, 9 milliseconds
for process P3, and 0 milliseconds for process P4. Thus, the average waiting time is (3 + 16 + 9 +
0)/4 = 7 milliseconds. By comparison, if we were using the FCFS scheduling scheme, the
average waiting time would be 10.25 milliseconds.
The SJF scheduling algorithm is provably optimal, in that it gives the minimum average waiting
time for a given set of processes. Moving a short process before a long one decreases the waiting
time of the short process more than it increases the waiting time of the long process.
Consequently, the average waiting time decreases.
3. PRIORITY SCHEDULING:
The SJF algorithm is a special case of the general priority scheduling algorithm. A
priority is associated with each process, and the CPU is allocated to the process with the
highest priority. Equal-priority processes are scheduled in FCFS order. An SJF algorithm
is simply a priority algorithm where the priority (p) is the inverse of the (predicted) next
CPU burst. The larger the CPU burst, the lower the priority and vice versa. 16 Note that
we discuss scheduling in terms of high priority and low priority. Some systems use low
numbers to represent low priority; others use low numbers for high priority. This
difference can lead to confusion. In this text, we assume that low numbers represent high
priority As an example, consider the following set of processes, assumed to have arrived
at time 0, in the order P1, l2, ..., P5. with the length of the CPU burst given in
milliseconds:
The average waiting time is 8.2 milliseconds.Priority scheduling can be either preemptive or
non-preemptive. When a process arrives at the ready queue, its priority is compared with the
priority of the currently running process. A preemptive priority scheduling algorithm will
preempt the CPU if the priority of the newly arrived process is higher than the priority of the
currently running process. A non-preemptive priority scheduling algorithm will simply put the
new process at the head of the ready queue.
4. ROUND-ROBIN SCHEDULING:
The round-robin (RR) scheduling algorithm is designed especially for timesharing
systems. It is similar to FCFS scheduling, but preemption is added to switch between
processes. A small unit of time, called a time quantum or time slice, is defined. A time
quantum is generally from 10 to 100 milliseconds. The ready queue is treated as a
circular queue. The CPU scheduler goes around the ready queue, allocating the CPU to
each process for a time interval of up to 1 time quantum. To implement RR scheduling,
we keep the ready queue as a FIFO queue of processes. New processes are added to the
tail of the ready queue. The CPU scheduler picks the first process from the ready queue,
sets a timer to interrupt after 1 time quantum, and dispatches the process.
The average waiting time under the RR policy is often long. Consider the following set of
processes that arrive at time 0, with the length of the CPU burst given in milliseconds:
If we use a time quantum of 4 milliseconds, then process Pi gets the first 4 milliseconds.
Since it requires another 20 milliseconds, it is preempted after the first time quantum, and
the CPU is given to the next process in the queue, process P2. Since process P2 does not
need 4 milliseconds, it quits before its time quantum expires. The CPU is then given to
the next process, process P3. Once each process has received 1 time quantum, the CPU is
returned to process P1 for an additional time quantum. The resulting RR schedule is:
The average waiting time is 17/3 = 5.66 milliseconds In the RR scheduling algorithm, no
process is allocated the CPU for more than 1 time quantum in a row . If a process’s CPU
burst exceeds 1 time quantum, that process is preempted and is put back in the ready
queue. The RR scheduling algorithm is thus preemptive.
PART B
(PART B : TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the concerned lab
in charge faculties at the end of the practical in case the there is no Black board access
available)
B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed above
and learning/observation noted in section B.3)
B.5 Question of Curiosity
(To be answered by student based on the practical performed and learning/observations)
Q1. Who schedule the process for CPU allocation and execution?