Scheduling of processes/work is done to finish the work on time.
Below are different time with respect to a process.
A typical process involves both I/O time and CPU time. In a uni programming system like MS-DOS, time spent waiting for I/O is wasted and CPU is free during this time. In multi programming systems, one process can use CPU while another is waiting for I/O. This is possible only with process scheduling.
Objectives of Process Scheduling Algorithm
Different Scheduling Algorithms
Some useful facts about Scheduling Algorithms:
Exercise:
Q.1. Which of the following is false about SJF?
S1: It causes minimum average waiting time
S2: It can cause starvation
(a) Only S1
(b) Only S2
(c) Both S1 and S2
(d) Neither S1 nor S2
Ans: d
Explanation: S1 is true SJF will always give minimum average waiting time.
S2 is true SJF can cause starvation.
Q.2. Consider the following table of arrival time and burst time for three processes P0, P1 and P2. (GATE-CS-2011)
The pre-emptive shortest job first scheduling algorithm is used. Scheduling is carried out only at arrival or completion of processes. What is the average waiting time for the three processes?
(a) 5.0 ms
(b) 4.33 ms
(c) 6.33
(d) 7.33
Ans: a
Explanation: Process P0 is allocated processor at 0 ms as there is no other process in the ready queue. P0 is preempted after 1 ms as P1 arrives at 1 ms and burst time for P1 is less than remaining time of P0. P1 runs for 4ms. P2 arrived at 2 ms but P1 continued as burst time of P2 is longer than P1. After P1 completes, P0 is scheduled again as the remaining time for P0 is less than the burst time of P2.
P0 waits for 4 ms, P1 waits for 0 ms and P2 waits for 11 ms. So average waiting time is (0 + 4 + 11) / 3 = 5.
Q.3. Consider the following set of processes, with the arrival times and the CPU-burst times given in milliseconds (GATE-CS-2004)
What is the average turnaround time for these processes with the preemptive shortest remaining processing time first (SRPT) algorithm?
(a) 5.50
(b) 5.75
(c) 6.00
(d) 6.25
Ans: a
Explanation:
The following is Gantt Chart of execution
Turn Around Time = Completion Time – Arrival Time
Avg Turn Around Time = (12 + 3 + 6 + 1) / 4 = 5.50
Q.4. An operating system uses the Shortest Remaining Time first (SRTF) process scheduling algorithm. Consider the arrival times and execution times for the following processes:
What is the total waiting time for process P2?
(a) 5
(b) 15
(c) 40
(d) 55
Ans: b
Explanation: At time 0, P1 is the only process, P1 runs for 15 time units.
At time 15, P2 arrives, but P1 has the shortest remaining time. So P1 continues for 5 more time units.
At time 20, P2 is the only process. So it runs for 10 time units
At time 30, P3 is the shortest remaining time process. So it runs for 10 time units
At time 40, P2 runs as it is the only process. P2 runs for 5 time units.
At time 45, P3 arrives, but P2 has the shortest remaining time. So P2 continues for 10 more time units.
P2 completes its execution at time 55
Total waiting time for P2 = Completion time - (Arrival time + Execution time)
= 55 - (15 + 25)
= 15
10 videos|99 docs|33 tests
|
1. What is CPU scheduling in operating systems? |
2. Why is CPU scheduling important in operating systems? |
3. What are the different types of CPU scheduling algorithms? |
4. What factors are considered while selecting a CPU scheduling algorithm? |
5. What are the advantages and disadvantages of Round Robin scheduling? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|