Process Scheduling Scheduler, scheduling algorithm in multiprogramming, what process to run on the CPU next and for how long job mix: timesharing, batch in background, mixture OS context switching code and clock interrupts are the mechanism, scheduler is policy Goals fairness, efficiency, response time, turnaround, throughput some of these involve trade-offs Preemptive versus run to completion (or non-preemptive) non-preemptive simple but not good for timesharing Preemptive -- time sharing systems round robin, context switching, time quantum, ready queue issue of big vs. small time slice modify RR with fixed priorities and keep ready queue in this order i.e. use priority classes with several queues e.g. President, VPs, Deans, dept heads, faculty, students or interactive and batch run highest queue RR and if empty run next highest queue RR, etc. starvation is a problem with this so use aging to decrease priorities as processes get time slices move a process down a queue after it has used up some slices also, longer time slice or more slices in lower priority queues another way to modify RR with dynamic priorities inverse of fraction of last quantum used to give IO bound jobs higher priority for better system utilization scheduler code (policy and mechanism) is complex due to handling interrupts get to see example code in the OS workshop course Non-preemptive -- batch systems FCFS is fair SJF, must know run times in advance minimizes average response time but large variance can adapt SJF to timesharing use past behavior as a guide: shortest estimated running time use weighted average of fractions of last time slices used as a way to prioritize the ready queue (think of each time slice an interactive job gets on the CPU as a separate "job") Fair Share scheduling guarantee to each user a percentage share of the CPU (based on priority or money paid) keep track of how much used compared to share run one with lowest ratio first to bring up its share to the guarantee Intermediate level scheduling (two-level) -<-------------------------------- | ^ v | input ==> long-term scheduler ==> CPU ===> short-term scheduler ===> output ^ | | swap v intermediate-term scheduler how long swapped in/out? how big (memory)? priority? accumulated CPU time? So what is good to use? RR, even for batch, with lower priority for batch jobs (command& in UNIX) and something to prevent starvation i.e. to make sure batch jobs still get some (small) percent of the CPU if there are interactive users See "Scheduling Fundamentals of SunOS 5.x" by John R. Graham in SunExpert --------- Vol. 6, No. 8, August 1995, pp. 55-63, for how threads are scheduled in Sun's Solaris (UNIX) OS, including real-time processes