اململكة العربية السعودية Kingdom of Saudi Arabia Ministry of Higher Education Prince Sattam Bin Abdul-Aziz University College of Computer Engineering and sciences وزارة التعليم العايل جامـعـة األمري سطام بن عبدالعزيز كل ـي ــة هـنــدس ــة وعلـ ــوم احلـاســب Course Title: CS3701-Operating System CSC3701 Instructor Name: Mr. Abdul Haseeb Khan Tutorial Lecture # 05 Date: - - -2015 Week# 05 2440 & 2544 :الشعبة CH: CPU Scheduling Objective: How CPU Schedule different tasks among different process in multiprogramming Q. 1. What is CPU scheduling? In multiprogramming CPU is switched among different processes in the memory. This is called CPU scheduling. Q. 2. Briefly describe CPU-I/O Burst cycle. Processes have the property that process execution consists of a cycle of CPU execution (CPU Burst) and I/O wait (I/O Burst). This property is important for success of CPU scheduling. Q. 3. What is the function of a CPU scheduler? When CPU becomes idle OS must select one of the processes in the ready queue to be executed on the CPU. This selection is carried out by CPU scheduler (also called short-term scheduler). Q. 4. What is the function of a dispatcher? Dispatcher gives control of the CPU to the process selected by CPU scheduler. It performs the context switch, switches to user mode and starts the program. Q. 5.What is non-preemptive and preemptive scheduling? Non-preemptive scheduling: When a process running on the CPU terminates or has to go into a wait state, CPU must be allocated to a new process. This is called nonpreemptive s cheduling or cooperative scheduling. Preemptive scheduling: When a process switches from running state to ready state or from a wait state to ready state, the scheduling done under this situation is called preemptive scheduling. Q. 6.Name the criteria used to judge scheduling algorithms. (a) CPU Utilization – percent of time CPU is busy (usually 40% to 90%) (b) Throughput – number of processes completing per unit time. (c) Turnaround time – time between process submission and completion. (d) Waiting time – time spent by a process waiting in the ready queue. (e) Response time – time between submissions of a request to the first response. Q. 7. Name and briefly describe various scheduling algorithms. (a) First Come First Served (FCFS) scheduling – the process that arrived first in the ready queue is given the CPU first. (b) Shortest Job First (SJF) scheduling – with each process is associated the length of its next CPU burst and the process with smallest next CPU burst is given the CPU. (c) Priority scheduling – a priority is associated with a process and CPU is given to the process of highest priority. (d) Round Robin scheduling – each process gets a small unit of CPU time (time quantum or time slice) usually 10 -100 milliseconds. When the time quantum finishes the process is added to the end of the ready queue. (e) Multilevel Queue scheduling – ready queue is partitioned into several separate queues. A process is permanently assigned to one queue based on some property of the process e.g. memory size, process priority. Each queue has its own scheduling algorithm. (f) Multilevel Feedback-queue scheduling – allows a process to move between queues according to CPU time requirements. If a process uses too much CPU time it is moved to a lower-priority queue. A process waiting too long in a lower priority queue is moved to a higher priority queue. Q. 8. What is the problem of starvation? How is it dealt with? A low priority process waiting indefinitely in the ready queue because of other high priority processes is said to be facing starvation. Solution to the problem of starvation is aging – a technique of slowly increasing the priority of processes that wait too long. Problem Solving Part Consider the following set of processes, with the length of CPU burst time given in milliseconds: Question # Process Arrival Time Burst Time P1 0 3 P2 1 1 P3 3 7 P4 4 0.5 P5 5 2 Draw the Gant charts illustrating the execution of these processes. i. FCFS: P1 P2 0 3 P3 P4 4 11 P5 11.5 13.5 SJF (NON-PRE-EMPTIVE): 0 ii. P1 P2 P4 P3 3 4 4.5 P5 11.5 13.5 What is the turnaround time of each process? FCFS: TAT: P1: 3 P2: SJF (Non-Preemptive) TAT: P1: 3 iii. 3 P2: 3 P3: 8 P4: 7.5 P5: 8.5 P3: 8.5 P4: 0.5 P5: 8.5 P3: 1 P4: 0.5 P5: 6.5 What is the waiting time of each process? FCFS: W.T: P1: 0 P2: 2 AWT: 3.3 SJF (Non-Preemptive) W.T: P1: 0 AWT: 2 P2: 2 P3: 1.5 P4: 0 P5: 6.5 Q Consider the following set of processes, with the length of CPU burst time given in milliseconds: Process P1 P2 P3 P4 P5 iv. Burst Time 3 1 8 5 2 Draw the Gant chart for SJF PRE-EMPTIVE: P1 0 v. P2 1 P1 2 P4 4 P5 5 P4 7 P3 11 19 What is the turnaround time of each process of the scheduling algorithm? SJF TAT: vi. Arrival Time 0 1 3 4 5 P1: 4 P2: 1 P3: 16 P4: 7 P5: 2 What is the waiting time of each process for each of the scheduling algorithm? SJF W.T: P1: 1 AWT: 1+0+8+2+0=11/5= P2: 0 P3: 8 P4: 2 P5: 0