updated Process management Chapter 2
updated Process management Chapter 2
Process
What is process?
A process is a program in execution.
Process Creation
A process can create several new processes through creating
process system calls during the process execution. Creating a
process we call it the parent process and the new process is a child
process.
Every new process creates another process forming a tree-like
structure. It can be identified with a unique process identifier that
usually represents it as pid which is typically an integer number.
Every process needs some resources like CPU time, memory, file,
I/O devices to accomplish.
Whenever a process creates a new process, there are two
possibilities in terms of execution, which are as follows −
• The parent continues to execute concurrently with its
children.
• The parent waits till some or all its children have terminated
.
There are two more possibilities in terms of address space of
the new process, which are as follows −
• The child process is a duplicate of the parent process.
• The child process has a new program loaded into it.
Process Termination
• The child has exceeded its usage of some of the resources that it
has been allocated. (To determine whether this has occurred, the
parent must have a mechanism to inspect the state of its
children.)
• The parent is exiting, and the operating system does not allow a
These are interprocess communication techniques that are used for client-server
based applications. A remote procedure call is also known as a subroutine call or a
function call.
A client has a request that the RPC translates and sends to the server. This request
may be a procedure or a function call to a remote server. When the server receives
the request, it sends the required response back to the client.
A diagram that illustrates remote procedure calls is given as follows −
Pipes
A pipe acts as a conduit allowing two processes to communicate. Pipes were
one of the first IPC mechanisms in early UNIX systems.
Ordinary Pipes:
Ordinary pipes allow two processes to communicate in standard producer–
consumer fashion: the producer writes to one end of the pipe (the write end)
and the consumer reads from the other end (the read end).
Named Pipes:
First-Come, First-Served Scheduling
0 2 3 7 10 13 14
p3 p1 p5 p2 p4
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
P1 7 7–3=4 4–4=0
P2 13 13 – 5 = 8 8–3=5
P3 2 2–0=2 2–2=0
P4 14 14 – 5 = 9 9–1=8
P5 10 10 – 4 = 6 6–3=3
Advantages
It is simple and easy to understand.
It can be easily implemented using queue data structure.
It does not lead to starvation.
Disadvantages:
It does not consider the priority or burst time of the
processes.
It suffers from convoy effect
AT : Arrival Time
BT : Burst Time or CPU Time
TAT : Turn Around Time
WT : Waiting Time
Processes AT BT CT TAT WT
P1 0 5 5 5-0 = 5 5-5 = 0
P2 0 3 8 8-0 = 8 8-3 = 5
P3 0 8 16 16-0 = 16 16-8 = 8
Consider the following table of arrival time and burst time for three
processes P1, P2 and P3
P1 5 ms 2 ms
P2 3 ms 0 ms
P3 4 ms 4 ms
Turnaround Time (TAT = Waiting Time (WT = TAT
Process Completion Time (CT)
CT – AT) – BT)
P2 3 ms 3 ms 0 ms
P1 8 ms 6 ms 1 ms
P3 12 ms 8 ms 4 ms
Code Implementation
Shortest Job First:
• SJF Scheduling can be used in both preemptive and non-preemptive
mode.
• Preemptive mode of Shortest Job First is called as Shortest Remaining
Time First (SRTF).
• for n processes, time complexity = nlog(n)
P1 P2 P4 P1 P3
0 1 5 10 17 26
0 1 2 3 4 5 6 7 8 9 10 11 12 13 16
p4 p2 p2 p1 p2 p2 p3 p3 p5 p5 p5 p4 p4 p4
0 1 3 4 6 8 11 16
p4 p2 p1 p2 p3 p5 p4
•Turnaround Time (TAT) = Completion Time - Arrival Time
Disadvantages
It can not be implemented practically since burst time of the
processes can not be known in advance.
It leads to starvation for processes with larger burst time.
Priorities can not be set for the processes.
Processes with larger burst time have poor response time.
Round Robin Scheduling:
p6 6 3
time quantum = 2 unit
Ready Queue:
P1, P2, P3, P1, P4, P5, P2, P6, P5, P2, P6, P5
0 2 4 6 8 9 11 13 15 17 18 19 21
p1 p2 p3 p1 p4 p5 p2 p6 p5 p2 p6 p5
Round Robin Scheduling:
Advantages
Disadvantages
It leads to starvation for processes with larger burst time as they have
to repeat the cycle many times.
Its performance heavily depends on time quantum.
Priorities can not be set for the processes.
Priority Scheduling:
Out of all the available processes, CPU is assigned to
the process having the highest priority.
In case of a tie, it is broken by FCFS Scheduling.
The waiting time for the process having the highest priority
will always be zero in preemptive mode.
The waiting time for the process having the highest priority
may not be zero in non-preemptive mode.
p1 0 4 2
p2 1 3 3
p3 2 1 4
p4 3 5 5
p5 4 2 5
0 4 9 11 12 15
p1 p4 p5 p3 p2
Priority Scheduling:
Advantages
Disadvantages
FCS is 28ms: