Professional Documents
Culture Documents
Lecture 2
Lecture 2 contents
Process in the hardware. Process States and control block Process Scheduling Scheduling: Behavior and Algorithms
Main Memory: Processes are Cash Memory: loaded in the selected Instructions are memory and process saved to increase the processing ready/waiting for execution
Temporary memory , nearer to the processor and faster than the main memory.
Processor: Run instruction by instruction Registry: Load a single instruction for a single running process
Process states
Process State (so running, ready, etc. is simply a field in the PCB ).
3: Processes
Ready Q And IO Qs
In many multitasking systems the processor scheduling subsystem operates on three levels Long term scheduling: which determines which programs are admitted to the system for execution and when, and which ones should be exited. selects which processes should be brought into the ready queue Short term scheduling (or dispatching): which determines which of the ready processes can have CPU resources, and for how long. selects which process should be executed next
3: Processes
Scheduling : definition
Interleave the execution of processes to maximize CPU utilization while providing reasonable response time The scheduler determines: o Who will run o When it will run o For how long
Process Scheduling
Interleave the execution of processes to maximize CPU utilization while providing reasonable response time.
Fairness: Comparable processes should get comparable service Efficiency: keep CPU and I/O devices busy Response time: minimize, for interactive users
Process Scheduling
Types of Scheduling
a context switch is the process of storing and restoring the state (context) of a process so that execution can be resumed from the same point at a later time.
Non-preemptive scheduling, a process runs until it terminates. Preemptive scheduling, even if the current process is still running, a context switch will occur when its time slice is used up.
Burst time is an assumption of how long a process requires the CPU between I/O waits. It can not be predicted exactly, before a process starts.
It means the amount of time a process uses the CPU for a single time. (A process can use the CPU several times before complete the job in the Preemptive scheduling)
Context Switch
A context switch is the switching of the CPU (central processing unit) from one process or thread to another. The steps of switching process A to process B are as follows:
Suspend As execution Transfer the control to the CPU scheduler. A CPU mode switch may be needed. Save As context to its PCB and other tables. Load Bs context to register, etc. Resume Bs execution of the instruction at Bs program counter. A CPU mode switch may be needed.
13
Scheduling Criteria
CPU utilization keep the CPU as busy as possible Throughput # of processes that complete their execution per time unit Turnaround time amount of time to execute a particular process Waiting time amount of time a process has been waiting in the ready queue Response time amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)
15
Scheduling: Algorithms
1. 2. 3. 4. 5. FCFS : First-come-first-served (Non-Preempt) SJF: Shortest job first (Non-Preempt) SRTF: Shortest Remaining Time First (Preempt) RR : Round robin (Preempt) Priority, Multilevel feedback queues (Preempt)
16
If they arrive in the order P1, P2, P3, we get: P1 0 Average waiting time: (0+24+27) / 3 = 17 P2 P3
24
27
30
If they arrive in the order P1, P2, P3, average waiting time 17
P2 0 3
P3 6
P1 30 (0+3+6) / 3 = 3
The CPU is assigned to the process that has the smallest next CPU burst In some cases, this quantity is known or can be approximated
Process
A B C D
FCFS schedule
A B C 7 A 7 12 11
12
SJF schedule
D 0 1
B
3
2. SJF
Arrival time
0 2 4 5
Burst time
7 4 1 5
P3
7 8
P2 12
P4 16
Arrival time
0 2 4 5
Burst time
7 4 1 5
P2(2)
(9+1+0+2) / 4 = 3 21
Each process gets a small unit of CPU time (time-quantum), usually 10-100 milliseconds
Time-quantum ~ switching time (or smaller) Fast response : relatively large waste of CPU time Time-quantum >> switching time long response (waiting) times, FCFS
Faster response
23
24
Select runnable process with highest priority When there are classes of processes with the same priority: o group priorities o each priority group may uses round robin scheduling o A process from a lower priority group runs only if there is no higher priority process waiting
Runnable processes
Lowest priority
Disadvantage?
26
5. M
Each process has a base priority increase priorities of waiting processes at each clock tick
increase priorities of I/O bound processes (decrease those of CPU bound processes) priority = 1/f (f is the fraction of time-quantum used)
27
Sample Question
In SJF (Shortest Job First) Scheduling method. How to calculate Average Waiting Time and average Turn-around time?
28
Sample Answer
Average waiting time=(0+2+2+3+3)/5=2 Average Turnaround time=(3+3+4+7+6)/5=4.6 Gantt chart is wrong... First process P3 has arrived so it will execute first. Since the burst time of P3 is 3sec after the completion of P3, processes P2,P4, and P5 has been arrived. Among P2,P4, and P5 the shortest burst time is 1sec for P2, so P2 will execute next. Then P4 and P5. At last P1 will be executed. Gantt chart for this ques will be: | P3 | P2 | P4 | P5 | P1 |
29
Operating Systems
Lecture 2