Os CH6
Os CH6
CPU Scheduler
• Selects from among the processes in memory that are ready to execute ( from a
ready queue ), and allocates the CPU to one of them.
• The selection process is carried out by the short-term scheduler ( or CPU
scheduler )
• CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state ( I/O request ).
2. Switches from running to ready state ( when interrupt occurs ).
3. Switches from waiting to ready ( completion of I/O ).
4. Terminates.
• Scheduling under 1 and 4 is nonpreemptive ( 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. Such as win 3.1
or Apple Macintosh ).
• All other scheduling is preemptive ( incurs a cost, assume that 2 processes
sharing data. One may be in the middle of updating the data when it is
preempted and the second process is running. The second process may
try to read the data which are currently in an inconsistent state).
Dispatcher
• Dispatcher module gives control of the CPU to the process selected by the short-
term scheduler; this function involves:
o switching context
o switching to user mode
o jumping to the proper location in the user program to restart that program
• Dispatch latency – time it takes for the dispatcher to stop one process and start
another running.
Optimization Criteria
• Max CPU utilization
• Max throughput
• Min turnaround time
• Min waiting time
• Min response time
• SJF (non-preemptive)
• SJF (preemptive)
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).
o Preemptive
o 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.
P2 P5 P1 P3 P4
0 1 6 16 18 19
• Performance
o q large ⇒ FIFO
o q small ⇒ q must be large with respect to context switch, otherwise
overhead is too high.