2Processes
2Processes
What is a process?
Structure of a process
Process state
Schedulers and Scheduling Queues
Context switching
Process creation and termination
Inter Process Communication
Dr. Manmath Narayan Sahoo
Department of Computer Science & Engineering
National Institute of Technology Rourkela
Odisha – 769008
Disclaimer – This slide is prepared taking content from various books and online resources. The presenter
doesn’t own the content. The inherited content is used for educational purpose only.
Process
• Process is a program that has initiated its execution.
• Program is passive entity stored on disk (executable file),
process is active
– Program becomes process when executable file loaded into
memory
• Execution of program started via GUI mouse clicks, command
line entry of its name, etc
• One program can be several processes
– Consider multiple users executing the same program
user and system data sections obviously may be different from one run of a process to another
5
Process Control Block (PCB)
• PCB - data structure that contains Information associated with each
process:
– Process ID
– Process State
– Program Counter
– Register Contents
– Starting address of the process
– Size of the process
– Pointer to Child Process
– Pointer to Next PCB (Sibling Pointer)
– Resource Pointer
Dr. Manmath N. Sahoo (CS) 6
Process Scheduling Queues
• Job queue – Set of all processes just created (new state
processes).
• Ready queue – set of all processes that are in main memory,
ready to execute (ready state processes).
• Device queues – set of processes waiting to use an I/O device
(waiting state processes).
9
Schedulers
• Long-term scheduler (LTS) (or job scheduler) → selects
10
Schedulers
• Short-term scheduler is invoked very frequently (milliseconds) ⇒ (must be fast).
• Long-term scheduler is invoked very infrequently (seconds, minutes) ⇒ (may be
slow).
• The long-term scheduler controls the degree of multiprogramming
• Long-term scheduler strives for good process mix of I/O-bound and CPU-bound
processes
– I/O-bound process →spends more time doing I/O than computations
– CPU-bound process → spends more time doing computations
– Only I/O bound processes → low CPU utilization
– Only CPU-bound processes → low device utilization
12
Context Switch
• When CPU switches to another process, the system must save
the state of the old process and load the saved state for the new
process.
• Context of a process represented in the PCB
• Context-switch time is overhead; the system does no useful
work while switching.
14
Process Creation
• Parent process create children processes, which, in turn create other
20
Message Passing System
W e b s e rv e r
S1 S2 S3 S4
o pe ra ti o n s :
H TTP S 1 : a cce pt co n n e cti o n
a pro ce s s S 2 : r e c e i ve ( r e q u e s t )
re qu e s t
S 3 : s e n d (re s po n s e )
a n o pe ra ti o n S 3 : di s co n n e ct
H TTP
C 1 : m a k e co n n e cti o n
re s po n s e
C 2 : s e n d (re qu e s t)
da ta fl o w C 3 : r e c e i ve ( r e s p o n s e )
C1 C2 C3 C4
C 4 : di s co n n e ct
W e b bro ws e r
b lo c k in g s en d s tarts an o p eratio n
ex ec u tio n flo w
ac k n o w led g em en t o f d ata rec eiv ed s u s p en d ed p erio d
b lo c k in g s en d retu rn s p ro v id ed b y th e IP C fac ility b lo c k in g rec eiv e en d s
Sync hr o no us Se nd and R e c e i ve
b lo c k in g r ec eiv e s tar ts
n o n b lo c k in g s en d
o p er atio n
ex ec u tio n f lo w
s u s p en d ed p er io d
b lo c k in g r ec eiv e r etu r n s
As ync hr o no us Se nd and
Sync hr o no us R e c e i ve
b lo c k in g s e n d is s u e d
n o n b lo c k in g r e c e iv e is s u e d
tr a n s p a r e n t a c k n o w le d g e m e n t
p r o v id e d b y th e I P C f a c ility e x e c u tio n f lo w
s u s p e n d e d p e r io d
S yn c h r o n o u s S e n d an d
As yn c h r o n o u s R e c e i ve
S c e n a r io A
n o n b lo c k in g r e c e iv e is s u e d
a n d r e tu r n e d im m e d ia te ly
b lo c k in g s e n d is s u e d
in d e f in ite
b lo c k in g e x e c u tio n f lo w
s u s p e n d e d p e r io d
P ro cess 2
P ro cess 1 S yn c h r o n o u s S e n d an d
As yn c h r o n o u s R e c e i ve
S c e n a r io B
n o n b lo c k in g r e c e iv e is s u e d
a n d r e tu r n e d im m e d ia te ly
b lo c k in g s e n d is s u e d
p r o c e s s is n o tif ie d
tr a n s p a r e n t a c k n o w le d g e m e n t o f th e a r r iv a l o f
p r o v id e d b y th e I P C f a c ility d a ta
e x e c u tio n f lo w
s u s p e n d e d p e r io d
S yn c h r o n o u s S e n d an d
As yn c h r o n o u s R e c e i ve
S c e n a r io C
t im e
r eq u es t 1
r es p o n s e 1
r eq u es t 2
in ter p r o c es s c o m m u n ic atio n
ex ec u tio n f lo w
r es p o n s e2
p r o c es s b lo c k ed
E ve nt di ag r am fo r a pr o to c o l
P r o c es s 1 P r o c es s 2
r ec eiv e f r o m p r o c es s 2 is s u ed
p r o c es s 1 b lo c k ed p en d in g d ata
f r o m p r o c es s 2 .
r ec eiv ed f r o m p r o c es s 1 is s u ed
p r o c es s 2 b lo c k ed p en d in g d ata
f r o m p r o c es s 1 .
m ain th r ead
n ew th r ead is s u es a b lo c k in g I P C o p er atio n
th r ead is b lo c k ed
m ain th r ead c o n tin u es w ith
o th er p r o c es s in g
th r ead is u n b lo c k ed af ter th e o p er atio n is f u lf illed