• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Module 3 part 2 process scheduling
 

Module 3 part 2 process scheduling

on

  • 447 views

 

Statistics

Views

Total Views
447
Views on SlideShare
447
Embed Views
0

Actions

Likes
0
Downloads
17
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Module 3 part 2 process scheduling Module 3 part 2 process scheduling Presentation Transcript

    • Module 3 – Process Scheduling Hemang Kothari Assistant Professor Computer Engineering Department MEFGI, Rajkot. Email: hemang.kothari@marwadieducation.edu.in Slides: http://www.slideshare.net/hemangkothari Computer Engineering Department - MEFGI 13/24/2014
    • 23/24/2014 Computer Engineering Department - MEFGI
    • Objective • Max CPU utilization • Max throughput • Min turnaround time • Min waiting time • Min response time 3/24/2014 Computer Engineering Department - MEFGI 3
    • Process Scheduling Goals • CPU utilization – keep the CPU as busy as possible • Throughput – # of processes that complete their execution per time unit • Turnaround time – amount of time to execute a particular process • Waiting time – amount of time a process has been waiting in the ready queue • Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) 3/24/2014 Computer Engineering Department - MEFGI 4
    • Background Work • Maximum CPU utilization obtained with Multiprogramming • CPU–I/O Burst Cycle. 3/24/2014 Computer Engineering Department - MEFGI 5
    • CPU Schedular • Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. • CPU scheduling decisions may take place when a process: 1.Switches from running to waiting state. 2.Switches from running to ready state. 3.Switches from waiting to ready. 4.Terminates. • Scheduling under 1 and 4 is nonpreemptive. • All other scheduling is preemptive. 3/24/2014 Computer Engineering Department - MEFGI 6
    • First-Come, First-Served (FCFS) Scheduling 3/24/2014 Computer Engineering Department - MEFGI 7 Process Burst Time P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: • Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17 • Average turn around time: (24 + 27 + 30) / 3 = 81/3 = 27 P1 P2 P3 24 27 300
    • First-Come, First-Served (FCFS) Scheduling 3/24/2014 Computer Engineering Department - MEFGI 8 Suppose that the processes arrive in the order P2 , P3 , P1 . • The Gantt chart for the schedule is: • Waiting time for P1 = 6; P2 = 0; P3 = 3 • Average waiting time: (6 + 0 + 3)/3 = 3 • Much better than previous case. • Convoy effect short process behind long process P1P3P2 63 300
    • Review - FIFO • Suppose the following jobs arrive for processing at the times indicated, each job will run the listed amount of time. • Give Gantt charts illustrating the execution of these jobs using FCFS scheduling algorithms. Compute the average turn around time and average waiting time. 3/24/2014 Computer Engineering Department - MEFGI 9 Remember that turnaround time is finishing time minus arrival time, so you have to subtract the arrival times to compute the turnaround times.
    • Shortest Job First (SJF) • Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. • Two schemes: – nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst. – preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). • SJF is optimal – gives minimum average waiting time for a given set of processes. 3/24/2014 Computer Engineering Department - MEFGI 10
    • Example of Non Preemptive SJF 3/24/2014 Computer Engineering Department - MEFGI 11 Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (non-preemptive) • Average waiting time = (0 + 6 + 3 + 7)/4 ≈ 4 P1 P3 P2 73 160 P4 8 12
    • Review - Non Preemptive SJF • Suppose the following jobs arrive for processing at the times indicated, each job will run the listed amount of time. • Give Gantt charts illustrating the execution of these jobs using SJF scheduling algorithms. Compute the average turn around time and average waiting time. 3/24/2014 Computer Engineering Department - MEFGI 12
    • Example of Preemptive SJF 3/24/2014 Computer Engineering Department - MEFGI 13 Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (preemptive) • Average waiting time = (9 + 1 + 0 +2)/4 = 3 P1 P3P2 42 110 P4 5 7 P2 P1 16
    • Review - Preemptive SJF • Suppose the following jobs arrive for processing at the times indicated, each job will run the listed amount of time. • Give Gantt charts illustrating the execution of these jobs using SJF scheduling algorithms. Compute the average turn around time and average waiting time. 3/24/2014 Computer Engineering Department - MEFGI 14
    • Priority Scheduling • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority (smallest integer highest priority). – Preemptive – nonpreemptive • SJF is a priority scheduling where priority is the predicted next CPU burst time. • Problem Starvation – low priority processes may never execute. • Solution Aging – as time progresses increase the priority of the process. 3/24/2014 Computer Engineering Department - MEFGI 15
    • 16 Priority Scheduling: Example Process Duration Priority Arrival Time P1 6 4 0 P2 8 1 0 P3 7 3 0 P4 3 2 0 0 8 P4 (3) P1 (6)11 P3 (7) 18 P2 waiting time: 0 P4 waiting time: 8 P3 waiting time: 11 P1 waiting time: 18 The average waiting time (AWT): (0+8+11+18)/4 = 9.25 (worse than SJF) P2 (8) 24
    • Round Robin • Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. • If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. • Performance – q large FIFO – q small q must be large with respect to context switch, otherwise overhead is too high. 3/24/2014 Computer Engineering Department - MEFGI 17
    • Round Robin with Quantum = 20 3/24/2014 Computer Engineering Department - MEFGI 18 Process Burst Time P1 53 P2 17 P3 68 P4 24 • The Gantt chart is: • Typically, higher average turnaround than SJF, but better response. P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162
    • Example of RR with Time Quantum = 20 • Waiting Time: – P1: (68-20)+(112-88) = 72 – P2: (20-0) = 20 – P3: (28-0)+(88-48)+(125-108) = 85 – P4: (48-0)+(108-68) = 88 • Completion Time: – P1: 125 – P2: 28 – P3: 153 – P4: 112 • Average Waiting Time: (72+20+85+88)/4 = 66.25 • Average Completion Time: (125+28+153+112)/4 = 104.5 A process can finish before the time quantum expires, and release the CPU. Lec 3 Operating Systems 19
    • Review • Five batch jobs A through E , arrive at a computer center at almost the same time. They have estimated running times of 10, 6, 2, 4, and 8 minutes. Their (externally determined) priorities are 3, 5, 2, 1, and 4, respectively, with 5 being the highest priority. For each of the following scheduling algorithms, determine the mean process turnaround time. Ignore process switching overhead. (a) Round robin. (b) Priority scheduling. (c) First-come, first-served (run in order 10, 6, 2, 4, 8). (d) Shortest job first. • For (a), assume that the system is multiprogrammed, and that each job gets its fair share of the CPU. For (b) through (d) assume that only one job at a time runs, until it finishes. All jobs are completely CPU bound. 3/24/2014 Computer Engineering Department - MEFGI 20
    • Solution • For round robin, during the first 10 minutes each job gets 1/5 of the CPU. At the end of 10 minutes, C finishes. During the next 8 minutes, each job gets 1/4 of the CPU, after which time D finishes. Then each of the three remaining jobs gets 1/3 of the CPU for 6 minutes, until B finishes, and so on. The finishing times for the five jobs are 10, 18, 24, 28, and 30, for an average of 22 minutes. • For priority scheduling, B is run first. After 6 minutes it is finished. The other jobs finish at 14, 24, 26, and 30, for an average of 18.8 minutes. • If the jobs run in the order A through E, they finish at 10, 16, 18, 22, and 30, for an average of 19.2 minutes. • Finally, shortest job first yields finishing times of 2, 6, 12, 20, and 30, for an average of 14 minutes. 3/24/2014 Computer Engineering Department - MEFGI 21
    • Review Job Time Arrival Priority 1 8 0 3 2 4 0 2 3 6 0 1 4 1 0 4 • All jobs arrive at time 0(but in the order 1, 2, 3&4).Draw charts and calculate the average time to complete (turn-around time) using the following scheduling algorithms: FCFS, SJF, Priority scheduling and round Robin (t=2) 3/24/2014 Computer Engineering Department - MEFGI 22
    • Out of Subject Context - Technical • Chaos Theory “ Chaos: When the present determines the future, but the approximate present does not approximately determine the future “ • Watch “ Butterfly Effect “ Movie - Thriller 3/24/2014 Computer Engineering Department - MEFGI 23