CPU Scheduling | Operating System - Computer Science Engineering (CSE) PDF Download

CPU Scheduling

Scheduling of processes/work is done to finish the work on time.

Below are different time with respect to a process.

Arrival Time:              Time at which the process arrives in the ready queue.
Completion Time:     Time at which process completes its execution.
Burst Time:                Time required by a process for CPU execution.
Turn Around Time:   Time Difference between completion time and arrival time.          
Turn Around Time = Completion Time - Arrival Time

Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time - Burst Time

Why do we need scheduling?

A typical process involves both I/O time and CPU time. In a uniprogramming system like MS-DOS, time spent waiting for I/O is wasted and CPU is free during this time. In multiprogramming 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

Max CPU utilization [Keep CPU as busy as possible]
 Fair allocation of CPU.
 Max throughput [Number of processes that complete their execution per time unit]
 Min turnaround time [Time taken by a process to finish execution]
 Min waiting time [Time a process waits in ready queue]
 Min response time [Time when a process produces first response]

Different Scheduling Algorithms

First Come First Serve (FCFS): Simplest scheduling algorithm that schedules according to arrival times of processes.

Shortest Job First(SJF): Process which have the shortest burst time are scheduled first.

Shortest Remaining Time First(SRTF): It is preemptive mode of SJF algorithm in which jobs are schedule according to shortest remaining time.

Round Robin Scheduling: Each process is assigned a fixed time in cyclic way.

Priority Based scheduling (Non Preemptive): In this scheduling, processes are scheduled according to their priorities, i.e., highest priority process is schedule first. If priorities of two processes match, then schedule according to arrival time.

Highest Response Ratio Next (HRRN) In this scheduling, processes with highest response ratio is scheduled. This algorithm avoids starvation.

Response Ratio = (Waiting Time + Burst time) / Burst time

Multilevel Queue Scheduling: According to the priority of process, processes are placed in the different queues. Generally high priority process are placed in the top level queue. Only after completion of processes from top level queue, lower level queued processes are scheduled.

Multi level Feedback Queue Scheduling: It allows the process to move in between queues. The idea is to separate processes according to the characteristics of their CPU bursts. If a process uses too much CPU time, it is moved to a lower-priority queue.

Some useful facts about Scheduling Algorithms:
1) FCFS can cause long waiting times, especially when the first job takes too much CPU time.

2) Both SJF and Shortest Remaining time first algorithms may cause starvation. Consider a situation when long process is there in ready queue and shorter processes keep coming.

3) If time quantum for Round Robin scheduling is very large, then it behaves same as FCFS scheduling.

4) SJF is optimal in terms of average waiting time for a given set of processes,i.e., average waiting time is minimum with this scheduling, but problems is, how to know/predict time of next job.

Exercise:
1. Consider a system which require 40 time units of burst time.The Multilevel feedback queue scheduling is used and time quantum is 2 unit for top queue and is incremented by 5 unit at each level, then in what queue the process will terminate the execution?

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
Answer (D)
S1 is true SJF will always give minimum average waiting time.
S2 is true SJF can cause starvation 

Consider the following table of arrival time and burst time for three processes P0, P1 and P2.

Process   Arrival time   Burst Time
P0            0 ms          9 ms
P1            1 ms          4 ms
P2            2 ms          9 ms

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
Solution :
Answer: – (A)
Process P0 is allocated processor at 0 ms as there is no other process in 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.

Consider the following set of processes, with the arrival times and the CPU-burst times given in milliseconds.

Process   Arrival Time    Burst Time
    P1          0              5
    P2          1              3
    P3          2              3
    P4          4              1

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
Answer (A)
Solution:
The following is Gantt Chart of execution 

P1
P2
P4
P3
P1
1
4
5
8
12


Turn Around Time = Completion Time – Arrival Time
Avg Turn Around Time  =  (12 + 3 + 6+  1)/4 = 5.50

The document CPU Scheduling | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on CPU Scheduling - Operating System - Computer Science Engineering (CSE)

1. What is CPU scheduling in computer science engineering?
Ans. CPU scheduling is a technique used by operating systems to manage the execution of processes on a computer's central processing unit (CPU). It determines the order in which processes are executed and aims to maximize CPU utilization and overall system performance.
2. What are the different types of CPU scheduling algorithms?
Ans. There are several types of CPU scheduling algorithms, including: 1. First-Come, First-Served (FCFS): The simplest algorithm that executes processes in the order they arrive. 2. Shortest Job Next (SJN): Prioritizes processes with the shortest burst time first. 3. Round Robin (RR): Allocates a fixed time quantum to each process in a cyclic manner. 4. Priority Scheduling: Assigns priorities to processes and executes them based on their priority level. 5. Multilevel Queue Scheduling: Divides processes into different queues based on priority, with each queue having its own scheduling algorithm.
3. How does the First-Come, First-Served (FCFS) scheduling algorithm work?
Ans. The FCFS scheduling algorithm executes processes in the order they arrive. When a process enters the ready queue, it is allocated the CPU until it completes its execution or is blocked by an I/O request. The next process in the queue is then selected and given the CPU. This algorithm is simple but can lead to poor performance if long processes arrive first, causing shorter processes to wait unnecessarily.
4. What is the purpose of CPU scheduling?
Ans. The main purpose of CPU scheduling is to maximize CPU utilization and ensure efficient utilization of system resources. It aims to minimize the waiting time for processes in the ready queue, reduce the average turnaround time, and improve overall system performance. By efficiently scheduling processes, the operating system can effectively manage the execution of multiple tasks on a single CPU.
5. How does the Round Robin (RR) scheduling algorithm work?
Ans. The Round Robin scheduling algorithm allocates a fixed time quantum to each process in a cyclic manner. Each process is given a small time slice to execute, typically ranging from a few milliseconds to a few hundred milliseconds. If a process completes its execution within the time quantum, it is removed from the CPU. If not, it is moved to the end of the ready queue, and the next process in line is given a chance to execute. This algorithm ensures fairness among processes and prevents starvation of long-running processes.
10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

study material

,

Previous Year Questions with Solutions

,

ppt

,

CPU Scheduling | Operating System - Computer Science Engineering (CSE)

,

pdf

,

practice quizzes

,

Summary

,

Sample Paper

,

video lectures

,

mock tests for examination

,

Important questions

,

Viva Questions

,

MCQs

,

CPU Scheduling | Operating System - Computer Science Engineering (CSE)

,

shortcuts and tricks

,

Exam

,

past year papers

,

Semester Notes

,

Objective type Questions

,

CPU Scheduling | Operating System - Computer Science Engineering (CSE)

,

Free

,

Extra Questions

;