Академический Документы
Профессиональный Документы
Культура Документы
CONTACT SESSION 8
Process Management
Prof. C R Sarma
BITS Pilani Guest Faculty, BITS
Pilani Campus
7.1. Concept of Process 3.1 (105-107)
7.2. Process State Diagram 3.1.2 (107-110)
7.7.* Process Scheduling criteria 3.2 (110-115)
7.3. Operations on Processes 3.3 (115-122)
7.4. Inter-process communications 3.4-3.5 (122-130)
7.4. Inter-process communications with examples 3.4-3.5 (130-136)
7.5. Process vs. Threads 4.1 (163-166)
7.6. Multithreading Models 4.3 (169-171)
7.8. Process Scheduling Algorithms -FCFS, SJF, Priority 6.3 (266-270)
7.8. contd.. - RR, Multilevel Queue, Multilevel Feedback Queue 6.3.3 (270-277)
Process Management
At any point of time one Job might be running and others are in not running state.
•
Operating Systems 5
7 Operating Systems BITS Pilani, Pilani Campus
Two State Process Model
by interrupt signal
9 Operating Systems BITS Pilani, Pilani Campus
Queuing Diagram
– If we attempt to load Jobs as they are submitted, there may not be enough resource to execute
processes in efficient manner
– To efficiently execute processes, system may put a maximum limit on processes in ready queue
11 Operating Systems BITS Pilani, Pilani Campus
Valid State Transitions
• New to ready In the event when all ready processes get blocked on I/O one
by one, the system tries to bring in a process from new to ready
• Ready to running state and it is found no memory is available to accommodate this
• Running to exit process….
• Running to ready Swapping is performed
• Running to blocked to offline is done
• Blocked to ready
• Ready to exit
• Blocked to exit Swapping - an I/O operation.
enhancing performance.
The operating system can
suspended one process by
putting it in the Suspended
state and transferring it to
disk.
The space that is freed up in
the memory can then be
used to bring in another
process.
Needed when all the ready
processes get blocked
•
12 Operating Systems BITS Pilani, Pilani Campus
One & Two Suspend States
Blocked Blocked/suspended:
• Fairness
• Policy enforcement
• Efficiency
• Min.Response time • CPU Bound : Processes spend bulk of its time
• Min.Turn around time executing on processor and do very little I/O
• I/O Bound : Process spend very little time executing
• Min. Waiting Time on processor and do lot of I/O operation
• Max.Throughput
• Load Balancing • Mix of processes in the system can not be predicted
• Predictability
CPU utilization
•
•
Turnaround time
– Amount of time to execute a particular process (interval
from time of submission to time of completion of
process)
1 Operating Systems BITS Pilani, Pilani Campus
CPU Scheduling
CPU Scheduling
Short-term scheduler
Allows one processes to fully use the CPU in efficient, fast and
fair manner.
OS selects one of the processes in the ready queue to be
executed.
The Short-term scheduler (or CPU scheduler) implements it.
CPU Scheduling: Dispatcher
This module gives control of the CPU to the process selected by
the short-term scheduler.
Its function involve:
• Switching context
• Switching to user mode
• Executing program from last executed.
It should be given that it is invoked during every process switch.
The time taken by the dispatcher to stop one process and start
another process is known as the Dispatch Latency. Dispatch
Latency can be explained using the below figure:
TypesScheduling
Types of CPU Scheduling
Non-Preemptive Scheduling
Once allotted the CPU, the process keeps the it until it terminates or switching to waiting state.
Used in platforms which don’t have special hardwareneeded for preemptive scheduling.
Preemptive Scheduling
In this tasks are usually assigned with priorities-necessitating to run a certain task that has a
higher priority before another task although it is running.
The running task is interrupted and resumed after the priority task has finished its execution.
Scheduling Methods
CPU Utilization
Optimal use of CPU without waste of any CPU cycle (Ideally 100% of the time-40% typical).
Throughput
Total number of processes completed/unit time typically 10/sec.
Turnaround Time
Time taken to execute a particular processTime of admission- time of completion.
Waiting Time
Amount of time a process has been waiting in the ready queue to acquire to get control on
the CPU.
Load Average
Average number of processes residing in the ready queue waiting for their turn.
Response Time
Time taken from when a request was submitted until the first response is produced-
completion of process execution is final response.
CPU utilization and Throughput are maximised-rest are minimised for proper optimization.
Scheduling Algorithms
First Come First Serve(FCFS) Shortest-Job-First(SJF) Priority Scheduling
Round Robin(RR) Multilevel Queue Scheduling Multilevel Feedback Queue
CPU Scheduling
Long-Term Scheduling
Programs admitted for processing – Control
degree fmultiprogramming
Medium-Term Scheduling
Part of the swapping function.
Need to manage
multiprogramming
Short-Term Scheduling
Known as the dispatcher Executes
most frequently Invoked when an Blocked/Blocked/suspended:
event occurs –If
Ready queue is empty and insufficient memory is available then one of the blocked
--Clock interrupts --I/O interrupts process
- can be swapped out
-Operating system calls --Signals –If currently running process requires more memory
–If OS determines that ready process will require more memory
First Come First Serve(FCFS) Scheduling
Process arriving first, gets executed first - First In First Out) –used in Batch Systems.
PROCE BURST Process Wait time Time for Process to wait for
SS TIME for its turn their turns
P1=0 P2=25 P3=30 P4=37
P1 25 0 Total wait time upto P4
P2 5 0+25 Ttot=0+25+30+37=92
Average time is therefore
P3 7 0+25+5
Tavg=92/4 =9.25
P4 3 0+25+5+7
P1 P2 P3 P4
GANTT Chart- graphically depicts
Problems with SJF –NP: Arrival times different for processes -not available in the ready
queue at time 0- some arrive after some time causes process with short burst time have
to wait for the current process's execution to finish.
Leads to the problem of Starvation, where a shorter process has to wait for a long time
until the current longer process gets executed. This happens if shorter jobs keep coming
- can be solved using the concept of aging.
Shortest-Job-First(SJF) Premptive
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16………………………………39
P1 P2 P3 P4
P1 P2 P4 P2 P3 (7) P1
(1) (2) (3) (3) (24)…………………………………
Example
Shortest-Job-First(SJF) Premptive
from the GANTT chart figure out BT and fill the table)
Process No. Arrival Burst Time Completion Turn Waiting Response Each UNIT time checks for
Time Time Around Time Time
Time what is the shortest job
AT BT CT TAT WT RT (TAT=CT-AT
WT=TAT-BT
P1 0 ? 9 9 4 0
RT={CPU firstallotted time-AT}
P2 1 ? 4 3 0 0 RT=WT in non Preemptive
P3 2 ? 13 11 7 7
P4 4 ? 5 1 0 0
GANTT Chart
P1 P2 P2 P2 P4 P1 P1 P1 P1 P3
0 1 2 3 4 5 6 7 8 9 13
TAT=9,4,13
P2 P1 P4 P3
(5) (25) (3) (7)
Round Robin Scheduling
Fixed time allotted to each process, called quantum for execution.
Once a process is executed for given time it is preempted and next process executes its time.
Context switching is used to save states of preempted processes.
PROC BURST Round Allotted
ESS TIME Robin Time P1 waits …..
P2 waits …..
P1 25 1 6 P3 waits …..
P2 5 2 4 P4 waits …..
P3 7 3 5 Average waiting=( /4)=
P4 3 4 3
Average Turn Around Time=( )/4=
0……5 6……..9 10………14 15……17 18….23 24
P1 (6) P2 P3 P4 P1 (6)
(4) (5) (3)
RR scheduling algorithm, no process is allocated the CPU for more than 1 time quantum in a row
If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in
chunks of at most q time units.
Each process must wait no longer than (n − 1) × q time units until its next time quantum. For example, with five processes
and a time quantum of 20 milliseconds, each process will get up to 20 milliseconds every 100 milliseconds.
Round Robin Scheduling+-
How a Smaller Time Quantum Increases Context
In practice, need to balance short-job performance
Switches and long-job throughput:
– Typical time slice today is between 10ms –
100ms
– Typical context-switching overhead is 0.1ms –
1ms
– Roughly 1% overhead due to context-
switching
Response Ratio = (time spent waiting + expected service time)// expected service time
This method accounts for the age of the process and the shorter jobs are favored.
Favors CPU-bound Processes
An I/O bound process will use CPU for a time less than the time quantum and gets blocked for I/O
A CPU-bound process run for all its complete time slice and is put back into the ready queue (thus
getting in front of blocked processes)
A solution: Virtual Round Robin
When a I/O has completed, the blocked process is moved to an auxiliary queue which gets preference over the
main ready queue .
A process dispatched from the auxiliary queue runs no longer than the basic time quantum minus the time
spent running since it was selected from the ready queue
2 BITS Pilani, Pilani Campus
Multilevel QueueScheduling
Created for processes are easily classified into different groups.
For example: A common division is made between foreground(or interactive) processes and
background (or batch) processes.
These two types of processes have different response-time requirements, and so might have
different scheduling needs.
In addition, foreground processes may have priority over background processes.
Partitions the ready queue into several separate queues-The processes are permanently
assigned to one queue based memory size, process priority, or process type.
Each queue has its own scheduling algorithm.
For example: separate queues might be used for foreground and background processes. The
foreground queue might be scheduled by Round Robin algorithm, while the background queue
is scheduled by an FCFS algorithm.
In addition, there must be scheduling among the queues, which is commonly implemented as
fixed-priority preemptive scheduling. For example: The foreground queue may have absolute
priority over the background queue.
40 Each group
allowed to use hasOperating
a specified
Systems share of the BITS Pilani, Pilani Campus
Fair Share Scheduling
•
Values defined
– Pj(i) = Priority of process j at beginning of ith
–
interval
Uj (i)
– = Processor use by process j during ith interval
GUk(i) = Processor use by group k during ith interval
–
CPUj(i) = Exponentially weighted average for process j
from beginning to the start of ith interval
–
GCPUk(i) = Exponentially weighted average for group k
from beginning to the start of ith interval
–
Wk = Weight assigned to group k, 0 Wk 1, kWk=1
=> CPUj(1) = 0, GCPUk(1) = 0, i =
1,2,3,….
41 Operating Systems BITS Pilani, Pilani Campus
Fair Share Scheduling
•
Values defined
– Pj(i) = Priority of process j at beginning of ith
–
interval
Uj (i)
– = Processor use by process j during ith interval
GUk(i) = Processor use by group k during ith interval
–
CPUj(i) = Exponentially weighted average for process j
from beginning to the start of ith interval
–
GCPUk(i) = Exponentially weighted average for group k
from beginning to the start of ith interval
–
Wk = Weight assigned to group k, 0 Wk 1, kWk=1
=> CPUj(1) = 0, GCPUk(1) = 0, i =
1,2,3,….
42 Operating Systems BITS Pilani, Pilani Campus
Fair Share Example
•
Three processes A, B, C; B,C are in one group; A is by itself
•
Both groups get 50% weighting
Process A Process B Process C
Priority Process Group Priority Process Group Priority Process Group
t=0 60 0 0 60 0 0 60 0 0
A +60 +60
t=1 90 30 30 60 0 0 60 0 0
B +60 +60 +60
t=2 74 15 15 90 30 30 75 0 30
A +60 +60
t=3 96 37 37 74 15 15 67 0 15
C +60 +60 +60
t=4 78 18 18 81 7 37 93 30 37
A +60 +60
t=5 98 39 39 70 3 18 76 15 18
B +60 +60 +60
t=6 78 19 19 94 31 39 82 7 39
A +60 +60
t=7 98 39 39 76 15 19 70 3 19
C +60 +60 +60
t=8 78 19 19 82 7 39 94 31 39
A +60 +60
t=9 98 39 39 70 3 19 76 15 19
B +60 +60 +60
t=10 78 19 19 94 31 39 82 7 39
A +60 +60
t=11 98 39 39 76 15 19 70 3 19
C +60 +60 +60
t=12 78 19 19 82 7 39 94 31 39
Operating Systems BITS Pilani, Pilani Campus
Traditional UNIX Scheduling
•
Multilevel queue using round robin within each of the priority
•
queues Priorities are recomputed once per second
•
Base priority divides all processes into fixed bands of priority levels
•
Adjustment factor used to keep process in its assigned band (called
nice)
P2 1 4 3 0 0
P3 2 13 11 7 7
P4 4TAT 5 1 0 0
GANTT Chart
P1 P2 P2 P2 P4 P1 P1 P1 P1 P3
0 1 2 3 4 5 6 7 8 9 13
TAT=9,4,13
P4
GANTT Chart
P1 P2 P2 P2 P4 P1 P1 P1 P1 P3
0 1 2 3 4 5 6 7 8 9 13