1 / 15

Scheduling Algorithms (cont.) (Operating Systems)

Scheduling Algorithms (cont.) (Operating Systems). Nuhara Jabbar. Priority Scheduling. A priority is associated with each process. The CPU is allocated to the process with the highest priority. Equal-priority processes are scheduled in FCFS order.

ddarryl
Download Presentation

Scheduling Algorithms (cont.) (Operating Systems)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Scheduling Algorithms (cont.)(Operating Systems) NuharaJabbar

  2. Priority Scheduling • A priority is associated with each process. • 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

  3. Priority Scheduling (cont.) • Priorities are generally indicated by some fixed range of numbers • Some systems use low numbers to represent low priority; others use low numbers for high priority. This difference can lead to confusion. • we assume that low numbers represent high priority.

  4. Example • consider the following set of processes, assumed to have arrived at time 0, in the order P1, P2, • • , P5, with the length of the CPU burst given in milliseconds: Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2

  5. P2 P5 P3 P1 19 6 18 16 0 Example (cont.) • Using priority scheduling, we would schedule these processes according to the following Gantt chart: • The average waiting time is 8.2 milliseconds P4 1

  6. Priority scheduling • Priority scheduling can be either preemptive or nonpreemptive. • 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 nonpreemptive priority scheduling algorithm will simply put the new process at the head of the ready queue.

  7. exercises Assume the process set in the previous example, • Solve it using SJF algorithm (Gantt Chart and average waiting time). If the processes arrived in the following manner (p1 at 0, p2 at 3, p3 at 5, p4 at 6 and p5 at 7) • Schedule the process set using preemptive priority scheduling algorithm, compute the average waiting time and the average turn around time. • Schedule the process set using preemptive SJF scheduling algorithm (SRTF), compute the average waiting time and the average turn around time.

  8. Problem • In a heavily loaded computer system, a steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU. • This problem is called starvation. • A solution to the problem of starvation of low-priority processes is aging. • Aging is a technique of gradually increasing the priority of processes that wait in the system for a long time.

  9. Aging Example • if priorities range from 127 (low) to 0 (high). • Aging could increase the priority of a waiting process by 1 every 15 minutes. • Eventually, even a process with an initial priority of 127 would have the highest priority in the system and would be executed. • it would take less than 32 hours for a priority-127 process to age to a priority-0 process.

  10. Round-Robin Scheduling • Round-Robin Scheduling Algorithm 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.

  11. P1 P2 P3 P1 P1 P1 P1 P1 0 10 14 18 22 26 30 4 7 Example of RR, Time Quantum = 4 ProcessBurst Time P1 24 P2 3 P3 3 • The Gantt chart is: • The average waiting time is 17/3 = 5.66 milliseconds.

  12. Conclusions • 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. • For example, with five processes and a time quantum of 20 milliseconds, each process will get up to 20 milliseconds every 100 milliseconds.

  13. RR Performance • If the time quantum is large, the RR policy is the same as the FCFS policy. So, Is it good if the time quantum is small … ? • then q must be large with respect to context switch time • If the context-switch time is approximately 10 percent of the time quantum, then about 10 percent of the CPU time will be spent in context switching.

  14. Time Quantum and Context Switch

  15. Turnaround Time • In general, the average turnaround time can be improved if most processes finish their next CPU burst in a single time quantum. • given three processes of 10 time units each, and a quantum of 1 time unit, the average turnaround time is 29. • If the time quantum is 10, however, the average turnaround time drops to 20.

More Related