Escolar Documentos
Profissional Documentos
Cultura Documentos
Simma Rai
Basic Concept
In multiprogramming, multiple processes and threads competing for CPU at the same time
Scheduling
Scheduling
Set of policies and mechanisms that an OS supports for determining the order of execution of the pending jobs or processes
Scheduler
The part of the operating that makes the choice of which ready process to run next.
Scheduling algorithm
the algorithm Scheduler uses
Process Behavior
CPUI/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait I/0 burst : when a process enters the blocked state waiting for an external device to complete its work.
compute-bound processes:
spend most of their time computing long CPU bursts and thus infrequent I/0 waits
I/O-bound processes:
spend most of their time waiting for I/O short CPU bursts and thus frequent I/O waits key factor is the length of the CPU burst i.e. the duration of computing
Process Behavior
Levels/Types of Scheduler
1. long-term scheduler 2. mid-term or medium-term scheduler 3. short-term scheduler
Long-term scheduler
admission scheduler or high-level scheduler decides which jobs or processes are to be admitted to the ready queue (in the Main Memory) Admission of a process to the set of currently executing processes is either authorized or delayed by the long-term scheduler responsible for controlling the degree of multiprogramming long term queue exists in the Hard Disk or the "Virtual Memory"
Medium-term scheduler
Intermediate level Swapping in/out
removes processes from main memory and places them on secondary memory (such as a disk drive) or vice versa process which has not been active for some time, or has a low priority, or taking up a large amount of memory..
Short-term scheduler
Low level CPU scheduler decides which of the ready, in-memory processes are to be executed (allocated a CPU)
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
When to Schedule
1. New process created
Choice between parent process or the child process
2. Process exit
Which ready process need to be run
3. Process block
Select another process to run
4. I/O interrupt
decide whether to run the newly ready process or the process that was running at the time of the interrupt, or some third process
Batch systems
Throughput
maximize jobs per hour Eg: system that can perform 30 jobs per hr is better than one that completes 20 per hr
Policy enforcement
seeing that stated policy is carried out
Balance
keeping all parts of the system busy (balance between I/O bound and CPU bound processes)
Turnaround time
minimize time between submission and termination
CPU utilization
keep the CPU busy all the time
Real-time systems
Meeting deadlines
avoid losing data
Predictability
Proportionality
meet users' expectations
Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is:
P1 P2 P3
24
27
30
Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case
Disadvantage:
unfair for short job
four jobs A, B, C, and D with run times of 8, 4, 4, 4 min respectively Turnaround time for A is 8 minutes, for B is 12 minutes, for C is 16 minutes, and for D is 20 minutes for an average of 14 minutes. With SJF algorithm, turnaround times are now 4, 8, 12, and 20 minutes for an average of 11 minutes
2
3 4 Mean
a+b
a+b+c a+b+c+d (4a+3b+2c+d)/4
Conclusion:
a contributes more to the average than the other times, so it should be the shortest job, with b next, then c, and finally d as the longest as it affects only its own turnaround time.
Example of SJF
ProcessArrival Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7 P4 5.0 3 P P2 P4 3 P 1 SJF scheduling chart
0 3 9 16 24
Example of Shortest-remaining-time-first
Burst Time 8 4 9 5
P3 17 26
too long
may cause poor response to short interactive requests Eg: If process switch- 1ms & quantum- 100ms, only 1% CPU wastage on pre-emption overhead but if there are 50 requests, the last request will get CPU only after 5s i.e. sluggish
Priority Scheduling
all processes may not be equally important. RR does not considers this PS algorithm does
Eg: On PC, a daemon process sending electronic mail in the background should be assigned a lower priority than a process displaying a video film on the screen in real time.
each process is assigned a priority the runnable process with the highest priority is allowed to run Priority Adjustment needed to prevent high-priority processes from running indefinitely. Two ways:
priority decreased along with time. Once the running process priority is less than the other, process switch occurs processes are allocated quantum. Highest priority processes allowed to run first
Priority assignment
Static Dynamic