Lecture 21: Introduction to Process Scheduling
Review: Processes & Threads Resource ownership – Process or Task Scheduling/execution – Thread or lightweight process One process, one thread (MS-DOS) One process, multiple threads (Java Runtime) Multiple processes, one thread per process (Unix) Multiple processes, multiple threads (W2K, Solaris, Linux)
Review: Single Threaded and Multithreaded Process Models
Review: Process/Thread States Possible process states running blocked ready
Process behavior Different Types of jobs have different demands a CPU-bound process an I/O bound process
Process Scheduling When to run a different process? Which one to run?
When to schedule process New process is created Process terminates A process blocks on I/O, semaphore, etc. I/O interrupt occurs Hardware clock interrupts
Preemptive vs. Non-preemptive Non-preemptive Scheduling: Processes run until they have finished or block for I/O Preemptive Scheduling: Can forcibly suspend a process and switch to another Hardware Clock Interrupt helps in implementing preemption
Categories of Process Scheduling Batch Systems (Compute Servers) Many processes, not interactive, throughput is important Interactive Systems PC Real Time Systems Guaranteed response times, meet deadlines
Scheduling Algorithm Goals All Systems Fairness – giving each process a fair share of the CPU Policy enforcement – seeing that stated policy is carried out Balance – keeping all parts of the system busy
Scheduling Algorithm Goals Batch Systems Throughput – maximize jobs per hour Turnaround time – minimize time between submission and termination CPU utilization – keep the CPU busy all the time
Scheduling Algorithm Goals Interactive Systems Response time – respond to requests quickly Proportionality – meet users’ expectations
Scheduling Algorithm Goals Real-time Systems Meeting deadlines – avoid losing data Predictability – avoid quality degradation in multimedia systems
First Come First Serve (FCFS) Maintain queue of processes Schedule first in queue Scheduled job executes until it finishes or blocks for I/O Simple, easy to implement Not good for mix of short and long jobs Example: a short job arriving soon after a long one
FCFS Arrival time CPU burst P1: 4 36 8 112 1 13 I/O burst 16 13 16 20 P1: 4 36 8 112 1 I/O burst P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1
FCFS 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Which process goes next? P1 idle P2 P3 P4 0 4 13 36 40 42
FCFS Time next ready 40 76 60 192 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Which process goes next? P1 idle P2 P3 P4 0 4 13 36 40 42