240 likes | 324 Views
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
E N D
Computer Studies (AL) Process Management CPU Scheduling
Reference • Silberschatz, Galvin, Gagne “Operating System Concepts 6th edition”, 2003, Wiley • Stallings, “Operating Systems Internals and Design Principles”, 2001, Prentice Hall
Content • Basic concepts • Scheduling Criteria • Decision making (preemptive and non-preemptive • Scheduling Algorithm • FCFS • SJF • PS • RRS
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.
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
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
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
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
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.
Discussion • Any disadvantage of preemptive? • Incur greater overhead than nonpreemptive.
Discussion • Any disadvantages of using non-preemptive CPU scheduler? • Keep the job too long for processor.
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.
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.
Scheduling Algorithm • First-Come-First-Served (FCFS) • Shortest-Job-First (SJF) • Priority Scheduling (PS) • Round-Robin Scheduling (RRS)
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
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
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
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)
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.
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
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.
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
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.
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