Process
Prepared by Balaram Ghosal
Today we will learn..
Concept of Process
Process Scheduling
Operations on Process
Co-Operating Process
Inter Process Communication
Prepared by Balaram Ghosal IT@BPPIMT 2
Process concept
A process is an instance of a program in execution.
Program => Passive, but Process => Active.
Process held various attributes like
Hardware state
Memory
CPU
And the progress of process status.
Prepared by Balaram Ghosal IT@BPPIMT 3
State of Process
Prepared by Balaram Ghosal IT@BPPIMT 4
State of Process
NEW: The process is just being put together
READY: The process has all needed resources- waiting for the CPU only
RUNNING: Instructions being executed. This running process hold the
CPU.
WAITING: for an event (hardware, human or another process)
SUSPENDED: Another process has explicitly told this process to sleep. It
will be awakened when a process explicitly awakens it.
TERMINATED: The process is being torn apart.
Prepared by Balaram Ghosal IT@BPPIMT 5
Prepared by Balaram Ghosal IT@BPPIMT 6
Process Scheduling
• The act of Scheduling a process means changing the active PCB
pointed to by the CPU. Also called a context switch.
• Schedulers are often implemented so they keep all computer resources busy.
• allow multiple users to share system resources effectively
• to achieve a target quality of service
Prepared by Balaram Ghosal IT@BPPIMT 7
Switching of Process..
Prepared by Balaram Ghosal IT@BPPIMT 8
Scheduling Queue
Prepared by Balaram Ghosal IT@BPPIMT 9
Scheduling Queue
The Operating System maintains the following important
process scheduling queues −
Job queue − This queue keeps all the processes in the
system.
Ready queue − This queue keeps a set of all processes
residing in main memory, ready and waiting to execute. A new
process is always put in this queue.
Device queues − The processes which are blocked due to
unavailability of an I/O device constitute this queue.
Prepared by Balaram Ghosal IT@BPPIMT 10
Scheduling..
CPU utilization – keep the CPU as busy as possible
Throughput – number 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 and blocked 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)
Prepared by Balaram Ghosal IT@BPPIMT 11
Scheduling type…
Long-term : To add to the pool of processes to be
executed.
Medium-term : To add to the number of processes that
are in the main memory.
Short-term : Which of the available processes will be
executed by a processor?
IO scheduling: To decide which process’s pending IO
request shall be handled by an available IO device.
Prepared by Balaram Ghosal IT@BPPIMT 12
Long-term: which
process to admit
Medium-term: which
process to swap in or
out
Short-term: which
Prepared by Balaram Ghosal IT@BPPIMT
ready process to 13
execute next
Way of Scheduling
FCFS
SJF
Preemptive
Non-preemptive
Priority
Prepared by Balaram Ghosal IT@BPPIMT 14
First-Come, First-Served
Process Burst Time
P1 24
P2 3 P1 P2 P3
P3 3
0 24 27 30
• Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
• Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17
Prepared by Balaram Ghosal IT@BPPIMT 15
First-Come, First-Served continued..
Suppose that the processes arrive in the order
P2 , P3 , P1 .
• The Gantt chart for the schedule is:
P2 P3 P1
0 3 6 30
• Waiting time for P1 = 6; P2 = 0; P3 = 3
• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case.
Convoy effect short process behind long process
Prepared by Balaram Ghosal IT@BPPIMT 16
Shortest Job First
• Associate with each process the length of its next CPU burst. Use
these lengths to schedule the process with the shortest time.
• Two schemes:
• Non-preemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst.
• Preemptive – if a new process arrives with CPU burst length less
than remaining time of current executing process, preempt. This
scheme is know as the
Shortest-Remaining-Time-First (SRTF).
• SJF is optimal – gives minimum average waiting time for a given set
of processes.
Prepared by Balaram Ghosal IT@BPPIMT 17
Non-Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
P1 P3 P2 P4
0 3 7 8 12 16
Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Prepared by Balaram Ghosal IT@BPPIMT 18
Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
Average waiting time = (9 + 1 + 0 +2)/4 = 3
Prepared by Balaram Ghosal IT@BPPIMT 19
Priority Scheduling
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority (smallest
integer highest priority).
Preemptive
Non-preemptive
SJF is a priority scheduling where priority is the predicted next CPU
burst time.
Problem Starvation – low priority processes may never execute.
Solution Aging – as time progresses increase the priority of the
process.
Prepared by Balaram Ghosal IT@BPPIMT 20
Round Robin
Each process gets a small unit of CPU time (time quantum), usually 10-100
milliseconds. After this time has elapsed, the process is preempted and
added to the end of the ready queue.
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 at
once. No process waits more than (n-1)q time units.
Performance
q large FIFO
q small q must be large with respect to context switch, otherwise
overhead is too high.
Prepared by Balaram Ghosal IT@BPPIMT 21
Round Robin example
Process Burst Time
P1 53 Time
P2 17 Quantum=20
P3 68
P4 24 P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
The Gantt chart is: 0 20 37 57 77 97 117 121 134 154 162
Typically, higher average turnaround than SJF, but better
response.
Prepared by Balaram Ghosal IT@BPPIMT 22
To be remind…
• Turn Around time = Exit time – Arrival time
• Waiting time = Turn Around time – Burst time
Prepared by Balaram Ghosal IT@BPPIMT 23
Problem
Find out AWT and ATAT for the following scheduling algorithm
a) FCFS, b) Non-preemptive priority, c) Preemptive priority and
Round Robin with time quantum 1ms.
Process Burst Priority Arrival time
P1 8 4 0
P2 6 1 2
P3 1 2 2
P4 9 2 1
P5 3 3 3
Prepared by Balaram Ghosal IT@BPPIMT 24
Many things left to do…!!
The document was prepared with exclusive help from lecture slide by B.
Ramamurthy available on
[Link]
And [Link] › Operating System › OS - Process Scheduling
Prepared by Balaram Ghosal IT@BPPIMT 25