Chapter 2 2 Process Scheduling Process concept n





























- Slides: 29
Chapter 2. 2 : Process Scheduling Process concept n Process scheduling n Interprocess communication n Deadlocks n Threads n 1
Scheduling n Select process(es) to run on processor(s) n Process state is changed from “ready” to “running” n The component of the OS which does the scheduling is called the scheduler 2
Types of Scheduling is divided into various levels. n These levels are defined by the location of the processes n A process can be n available to be executed by the processor n partially or fully in main memory n in secondary memory n is not started yet n 3
Types of Scheduling n Long Term Scheduling. n The decision to add to the pool of processes to be executed. n Medium Term Scheduling. n The decision to add to the process in main memory. n Short Term Scheduling. n The decision as to which process will gain the processor. n I/O Scheduling. n The decision as to which process's I/O request shall be handled by a device. 4
Scheduling Criteria Fairness : each process should get a fair share of the CPU n Efficiency: keep CPU 100% utilized n Response time : should be minimized for interactive users n Turnaround : minimize batch turnaround times n Throughput : maximize number of jobs processed per hour n 5
User-Oriented, Performance Criteria Response Time Turnaround Time Deadlines Aim low response time, maximum number of interactive users time between submission and completion maximise deadlines met 6
System-oriented, Performance Criteria Aim • Throughput allow maximum number of jobs to complete • Processor maximise percentage of time processor is busy utilisation • Overhead minimise time processor busy executing OS 7
System oriented, other criteria Criteria Aim Fairness treat processes the same avoid starvation Enforcing Priorities give preference to higher priority processes Balancing Resources keep the system resources busy 8
Important Factors n I/O boundedness of a process n CPU boundedness of a process n Is the process interactive or batch? n Process priority n Page fault frequency n Preemption frequency n Execution time received n Execution time required to complete 9
Types of Scheduling A scheduling algorithm is non-preemptive (run to completion) if the CPU cannot be taken away by the OS. n A scheduling algorithm is preemptive if the CPU can be taken away by the OS. n Cooperative Scheduling is the scheduling algorithm used by some operating systems (such as Windows versions up to 95 in which processes relinquish the control of CPU for some reason (I/O, waiting for some event etc. ) n 10
The Interrupting Clock n The OS sets the interrupting clock to generate an interrupt at some specified future time. n This interrupt time is the process quantum. n Provides reasonable response times and prevents the system being held up by processes in infinite loops. 11
Scheduling Algorithms n FCFS n Round Robin n Virtual Round Robin n Priority Classes n Shortest Job First n Shortest Remaining Time n Highest Response Ratio Next n Feedback Queues 12
FCFS (First Come First Serve) n Implementation: n As each process becomes ready, it joins the ready queue. n When the current process finishes the oldest process is selected next. n Characteristics: n Simple to implement n Nonpremptive n Penalises short and I/O-bound processes 13
Round Robin (RR) n Implementation: n Processes are dispatched FIFO. But are given a fixed time on the CPU (quantum - time slice). n Characteristics: n Preemptive n Effective in time sharing environments n Penalises I/O bound processes 14
Quantum Size n Some Options: n Large or small quantum n Fixed or variable quantum n Same for everyone or different n If quantum is to large RR degenerates into FCFS n If quantum is to small context switching becomes the primary job being executed n A good guide is quantum should be slightly larger than the time required for a typical interaction 15
Virtual Round Robin (VRR) n A modification to the RR algorithm to remove the bias towards CPU bound processes. n Implementation: n Two “ready” queues, one called an AUX queue for storing “completed” IO processes n AUX queue has priority over READY queue n IO processes only runs for remaining time n Characteristics: n Performance studies indicate fairer than RR 16
Priority n Implementation: n n Each process is assigned a priority and the scheduler always selects the highest priority process first Characteristics: High priority processes may run indefinitely, so decrease the priority of these processes at regular intervals n Assign high priority to system processes with known characteristics such as being I/O bound n 17
Priority Classes Priority Class 4 Highest Priority Class 3 Priority Class 2 Priority Class 1 Lowest 18
n Implementation: Processes are grouped into priority classes n Round Robin is used within a class n When selecting process start with the highest class. If the class is empty, use a lower class n n Characteristics: n If priorities are not adjusted from time to time, lower classes may starve to death 19
Shortest-Job-First (SJF) n Sometimes known as Shortest Process Next (SPN) n Implementation: n The process with the shortest expected execution time is given priority on the processor 20
n Characteristics: Nonpremptive n Reduces average waiting time over FIFO n Always produces the minimum average turnaround time n Must know how long a process will run n Possible user abuse n Suitable for batch environments. Not useful in a timesharing environment n 21
Shortest Remaining Time (SRT) n Preemptive counterpart of SPN n Implementation: n Process with the smallest estimated runtime to completion is run next n A running process may be preempted by a new process with a shorter estimate runtime 22
n Characteristics: n Still requires estimates of the future n Higher overhead than SJF n No additional interrupts are generated as in RR n Elapsed service times must be recorded 23
Highest Response Ratio Next (HRRN) n How do you get around the problem of Indefinite postponement? n Implementation: n Once a job gets the CPU it runs it to completion n The priority of a job is a function of the job's service time and the time it has been waiting for service priority = (time waiting + service time) / service time 24
n Characteristics: n Nonpremptive n Shorter jobs still get preference over longer jobs n However aging ensures long jobs will eventually gain the processor n Estimation still involved 25
Feedback Queues n Sometimes called multi-level feedback queues n Implementation: n. There is a network of ready queues n. A new process enters at the top queue n. Moves through the queue FIFO 26
n I/O processes: n If the job requires I/O before quantum expiration it leaves the network and comes back at the same level queue n CPU bound processes: n If the quantum expires first, the process is placed on the next lower queue n This continues until it reaches the bottom queue 27
n Dispatching: n. A process is only placed on the CPU if all higher level queues are empty n A running process is preempted by a process arriving in a higher queue n Processes from lower level queues receive a larger quantum n Modifications: n In some systems processes can proceed back up the network by becoming I/O bound 28
A Scheduling Mechanism Should: n Favour short jobs n Favour I/O bound jobs to get good I/O device utilisation n Determine the nature of a job and schedule accordingly 29