Process Management Notes
Process Management Notes
Process Management Notes
MANAGEMENT
Page 1 of 13
Introduction
Gone are the days when computer systems only had one program running at a time. In such
a case that single program had access to most if not all system resources. Now we have
multiple programs in memory executing simultaneously. Hence the need for process
management
What is a Process?
A process is primarily a program in execution. A program becomes a process when an
executable file is loaded into memory. It has four sections as depicted below.
Max
Stack
Heap
Data
Text
0
Figure 1 - Process in Memory
Stack: Used to store temporary variables, i.e. local variables, function and procedure
parameters etc – its size is known at compile time.
Heap: Gets allocated dynamically, size is not known at compile time;
Data: Stores global variables
Page 2 of 13
Process States
As a process executes, it changes state. The state of a process is defined in part by the current
activity of that process. Each process may be in one of the following states1:
New
Interrupted
Accepted
Ready Running
exit
By OS
Waiting
I/O or Event Complete I/O or Event Wait
1
These states and their names may differ across different operating systems
Page 3 of 13
Process state. The state may be new, ready, running, waiting and terminated.
Program counter The counter indicates the address of the next instruction to be executed
for this process.
CPU register The registers vary in number and type, depending on the
Information computer architecture. They include accumulators, index registers,
stack pointers, and general-purpose registers, plus any condition-code
information. This state information must be saved
when an interrupt occurs, to allow the process to be continued correctly
when it regains the CPU.
CPU-scheduling This information includes a process priority, pointers to scheduling
information queues, and any other scheduling parameters.
Memory- This includes the information of page table, memory limits, segment
management table depending on memory management technique used by the
information operating system. https://www.youtube.com/watch?v=p9yZNLeOj4s
Accounting This information includes the amount of CPU and real time used, time
information limits, account numbers, job or process numbers,
and so on.
I/O status This information includes the list of I/O devices allocated to the process,
information. a list of open files, and so on.
Process Scheduling
In a multiprogramming world maximizing CPU utilization is key i.e. some process should
always be running to avoid CPU idle time. The process scheduler must select an available
process for execution on a CPU core. Each core can run one process at a time. In general
processes can be categorized as either I/O-bound or CPU-bound.
Page 4 of 13
Process Scheduling Queues
The OS maintains all PCBs in Process Scheduling Queues. A separate queue for
each of the process states. PCBs of all processes in the same execution state are
placed in the same queue. As the state of a process changes, its PCB is removed
from its current queue and moved to its new state queue.
• 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.
Context Switch
Context switching is an essential part of a multitasking OS. A context switch is the
mechanism to store the state or context of a process losing the CPU and to restore the state
or context of a process gaining the CPU. This state is stored in the Process Control block so
that a process execution can be resumed from the same point later. A context switcher
enables multiple processes to share a single CPU.
When the scheduler switches the CPU from executing one process to execute another, the
state of the current running process is stored into the process control block. Next, the state
of the second process is loaded from its own PCB and used to set the Process Counter,
registers, etc. The second process can start executing.
Page 5 of 13
Schedulers
Schedulers are part of the OS that handle process scheduling in various ways. Their main
task is to select the jobs to be submitted into the system and to decide which process to run.
Three types of schedulers exist, although all three need not be present in an OS
• Priority: Scheduler may preempt a lower priority running process anytime a higher
priority process enters the ready state.
• Time-Slicing: Once a process has had use of the CPU for its designated time it must
yield the CPU
Page 6 of 13
First-Come First-Served (FCFS) Scheduling
Processes are assigned the CPU in the order they request it i.e. there is a single queue of
ready processes. When the first job enters the system, it is started immediately and allowed
to run as long as it wants to. It is not interrupted because it has run too long. As other jobs
come in, they are put onto the end of the queue. Should the running process blocks/waits,
the first process on the queue is run next. When a blocked/waiting process becomes ready,
like a newly arrived job, it is put on the end of the queue, behind all waiting processes.
Process Burst Time (ms) Consider the set of processes that arrive at time zero.
P1 5 The length of the CPU burst time given in millisecond.
P2 24 Now we will calculate the average waiting time,
P3 16 average turnaround time and throughput of FCFS.
P4 10
Burst Time = Time to execute
P5 3
P1 = 0 ms
P2 = 5 – 0 = 5 ms Average Waiting Time = Waiting Time All Processes / Number of Processes
P3 = 29 – 0 = 29 ms
(0+5+29+45+55)/5 = 26.8ms
P4 = 45 – 0 = 45 ms
P5 = 55 – 0 = 55 ms
(0+5+29+45+55)/5
Throughput
Total Burst Time / Number Processes
(5 + 24 + 16 + 10 + 3) /5 = 11.6ms i.e. 1 process executes every 11.6ms
Page 7 of 13
Shortest-Job-Next (SJN) Scheduling (Non-Preemptive/Cooperative)
Out of all available ready processes the scheduler selects the process with the shortest
execution time. This selected process will execute until completion. The scheduler will then
again select a process from the ready queue that has the shortest execution time.
Process Burst Time (ms) Consider the set of processes that arrive at time zero.
P1 5 The length of the CPU burst time given in millisecond.
P2 24 Now we will calculate the average waiting time,
P3 16 average turnaround time and throughput of SJN.
P4 10
Burst Time = Time to execute
P5 3
P5 = 0 ms
P1 = 3 – 0 = 3ms Average Waiting Time = Waiting Time All Processes / Number of Processes
P4 = 8 – 0 = 8ms
(0+3+8+18+34)/5 = 12.6 ms
P3 = 18 – 0 = 18ms
P3 = 34 – 0 = 34ms
Throughput
Total Burst Time / Number Processes
(5 + 24 + 16 + 10 + 3) /5 = 11.6ms i.e. 1 process executes every 11.6ms
Page 8 of 13
Shortest-Remaining Time (SRT) Scheduling (Preemptive)
The scheduler selects the process from the ready queue with the shortest execution time,
however should a new process enter the ready queue, that has a shorter execution time
then the remaining execution time of the currently executing process, it may pre-empt the
running process, i.e. it gains control of the CPU
P1 = 0ms
P2 = (3 – 2) + (10-4) = 7ms
Average Waiting Time = Waiting Time All Processes / Nr of Processes
P3 = 4 – 4 = 0ms
P4 = 15 – 6 = 9ms (0+7+0+9+0)/5 = 3.2ms
P5 = 8-8 =0ms
Page 9 of 13
Average Turnaround Time
Turnaround Time = Waiting time in ready queue + executing time + waiting time for I/O
Throughput
Total Burst Time / Number Processes
(3+6+4+5+2)/5 = 4ms i.e. 1 process executes every 4ms
P1 P2 P3 P1 P2 P3 P1 P1 P1 P1
0 5 10 15 20 21 24 29 34 39 44
P1 = (0 -0)+(15-5) + (24-20) = 14ms Average Waiting Time = Waiting Time All Processes / Nr of Processes
P2 = (5 – 0)+ (20-10) = 15ms
(14+15+16)/3 = 15ms
P3 = (10 – 0) + (21-15) = 16ms
Throughput
Total Burst Time / Number Processes
(30+6+8)/3 = 14.67ms i.e. 1 process executes every 14.67ms
Page 10 of 13
Priority Scheduling
Each process is assigned a priority, and the process in the ready queue with the highest
priority is allowed to run. Processes with same priority are executed on first come first served
basis.
Process Burst Time (ms) Priority
P1 6 2
Consider the set of processes that arrive at time
P2 12 4 zero. Each process is assigned a priority
P3 1 5
P4 3 1
P5 4 3
P4 P1 P5 P2 P3
0 3 9 13 25 26
P1 = (3 -0) = 3ms Average Waiting Time = Waiting Time All Processes / Nr of Processes
P2 = (13 – 0) = 13ms
(3+13+25+0+9)/5 = 10ms
P3 = (25 – 0) = 25ms
P4 = (0-0) = 0ms
P5 = (9-0) = 9ms
Throughput
Total Burst Time / Number Processes
(6+12+1+3+4)/5 = 5.2ms i.e. 1 process executes every 5.2ms
Page 11 of 13
https://www.youtube.com/watch?v=THqcAa1bbFU (Process Scheduling)
Page 12 of 13
Bibliography
Silberschatz, A., Baer Galvin, P., & Gagne, G. (2018). Operating System Concepts. Hoboken: John
Wiley & Sons, Inc.
Tannenbaum, A., & Bos, H. (2015). Modern Operating Systems. New Jersey: Pearson.
W3Schools. (2019, 01 01). Operating System Tutorial Library. Retrieved 2022, from W3Schools:
https://www.w3schools.in/operating-system-tutorial
Page 13 of 13