1 / 24

Computer Studies (AL)

Computer Studies (AL). Process Management CPU Scheduling. Reference. Silberschatz, Galvin, Gagne “Operating System Concepts 6 th edition”, 2003, Wiley Stallings, “Operating Systems Internals and Design Principles”, 2001, Prentice Hall. Content. Basic concepts Scheduling Criteria

thalia
Download Presentation

Computer Studies (AL)

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. Computer Studies (AL) Process Management CPU Scheduling

  2. Reference • Silberschatz, Galvin, Gagne “Operating System Concepts 6th edition”, 2003, Wiley • Stallings, “Operating Systems Internals and Design Principles”, 2001, Prentice Hall

  3. Content • Basic concepts • Scheduling Criteria • Decision making (preemptive and non-preemptive • Scheduling Algorithm • FCFS • SJF • PS • RRS

  4. Basic concept • The objective of multiprogramming is to have some process running at all times, in order to maximize CPU utilization. • Scheduling is a fundamental operating system function.

  5. CPU-I/O burst Cycle • The success of CPU scheduling depends on the following observed property of processes: • Process execution consists of a cycle of CPU execution and I/O wait. • Processes alternate between these two states. • Process execution begins with a CPU burst, followed by an I/O burst, and so on

  6. CPU scheduler • OS must select one of the processes in the ready queue to be executed. • The selection process is carried out by the short-term scheduler. • FIFO queue • Priority queue • Tree • Unordered linked list

  7. Scheduling decision take place... • CPU scheduling decisions may take place under the following 4 circumstances: • 1. When a process switches from running stat to the waiting state • 2. When a process switches from running state to the waiting state • 3. When a process switches from the waiting state to the ready state • 4. When a process terminates

  8. Non Preemptive CPU Scheduler • When scheduling takes place only under circumstances 1 and 4= Nonpreemptive scheduling scheme. • (since it’s no choice in terms of scheduling) • Under nonpreemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. • In order word, CPU scheduler is said to be non-preemptive if it reassigns the CPU only when a process gives up the use of the CPU. • E.g. Windows 3.1

  9. Preemptive Scheduling • When scheduling takes place at 2 and 3= preemptive scheduling scheme. • In order word, a CPU scheduler is said to be preemptive if it immediately assigns the CPU to a higher-priority process when the process requires CPU service.

  10. Discussion • Any disadvantage of preemptive? • Incur greater overhead than nonpreemptive.

  11. Discussion • Any disadvantages of using non-preemptive CPU scheduler? • Keep the job too long for processor.

  12. Discussion • Why preemptive? • Better service to the total population processes because they prevent any one process from monopolizing the processor for very long. • The cost of preemption may be kept relatively low by using efficient process-switching mechanisms (hardware design) or providing large main memory to keep a high percentage of programs in main memory.

  13. Scheduling Criteria • Different CPU-scheduling algorithm have different properties. • The criteria suggested include: • CPU utilization • Keep CPU busy • Throughput • The number of processes completed per time unit • Turnaround time • How long it takes to execute that process • (Waiting to get into memory + ready queue + execute + I/O) • Waiting time • Spends time on waiting in the reading queue • Response time • The time from the submission of a request until the first response is produced.

  14. Scheduling Algorithm • First-Come-First-Served (FCFS) • Shortest-Job-First (SJF) • Priority Scheduling (PS) • Round-Robin Scheduling (RRS)

  15. First-Come-First-Served (FCFS) • The process that requests the CPU first is allocated the CPU first 24 27 30 0 Average waiting time = (0+24+27)/3 = 17ms

  16. First-Come-First-Served (FCFS) • If the order is P2, P3 and P1 0 3 6 30 Average waiting time is now (6+0+3)/3 = 3ms

  17. Shortest-Job-First Scheduling (SJF) • When CPU is available, it is assigned to the process that has the smallest next CPU burst. 0 9 3 16 24 Average waiting time is (3+16+9+0)/4 = 7ms

  18. Shortest-Job-First Scheduling (SJF) • SJF is provably optimal, in that it gives the minimum average waiting time. • The read difficulty is knowing the length of the next CPU request.(that’s why SJF is used frequently in long-term scheduling)

  19. Shortest-Job-First Scheduling (SJF) • Preemptive SJF will preempt the currently executing process • Nonpreemptive SJF will allow the currently running process to finish its CPPU burst.

  20. Shortest-Job-First Scheduling (SJF) Process P1 is started at time 0, since it’s the only process in the queue. Process P2 arrives at time 1. The remaining time for P1 (7ms) is larger than the time requiredby process P2, so process P1 is preempted andprocess P2 is scheduled. Preemptive Average waiting time (preemptive) is((10-1)+(1-1)+(17-2)+(5-3))/4= 26/4 = 6.5ms 0 1 5 10 17 26 Nonpreemptive Average waiting time (Nonpreemptive)is ((0-0)+(8-1)+(12-3)+(17-2)/4 = 31/4 =7.75ms 0 8 12 17 26

  21. Priority Scheduling (PS) • 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.

  22. Priority Scheduling (PS) Major problem of PS is indefinite blocking(starvation) A low-priority process ever getting the CPU. Solution: AgingIt’s a technique of gradually increasing thepriority of processes that wait in thesystem for a long time. 0 1 6 16 18 19 Average waiting time = 8.2ms

  23. Round-Robin Scheduling (RRS) • Design for time-sharing system • Similar FCFS, with preemption • Small unit of time: time quantum/time slice • The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time quantum • Process less than 1 time quantum: release CPU voluntarily, then next process • Process more than 1 time quantum: time slice expired, context switch will be executed, process will be put at the tail of the ready queue, then next process.

  24. Round-Robin Scheduling • Average waiting time is quite long. Suppose time quantum: 4ms P1 gets the first 4ms, since it requiresanother 20ms, it’s preempted after thefirst quantum, and CPU is given to nextprocess P2. P2 doesn’t need 4ms, thenquits before time quantum expires. Thennext process P3 got the time quantum. 0 4 7 10 14 18 22 26 30 Average waiting time: 17/3 = 5.66

More Related