2. Process Management
2. Process Management
Process Management in OS
A Program does nothing unless its instructions are executed by a CPU. A program in
execution is called a process. In order to accomplish its task, process needs the
computer resources.
There may exist more than one process in the system which may require the same
resource at the same time. Therefore, the operating system has to manage all the
processes and the resources in a convenient and efficient way.
Some resources may need to be executed by one process at one time to maintain the
consistency otherwise the system can become inconsistent and deadlock may occur.
The operating system is responsible for the following activities in connection with
Process Management
Attributes of a process
The Attributes of the process are used by the Operating System to create the process
control block (PCB) for each of them. This is also called context of the process.
Attributes which are stored in the PCB are described below.
1. Process ID
When a process is created, a unique id is assigned to the process which is used for
unique identification of the process in the system.
2. Program counter
A program counter stores the address of the last instruction of the process on which
the process was suspended. The CPU uses this address when the execution of this
process is resumed.
3. Process State
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 2 of 9
The Process, from its creation to the completion, goes through various states which
are new, ready, running and waiting. We will discuss about them later in detail.
4. Priority
Every process has its own priority. The process with the highest priority among the
processes gets the CPU first. This is also stored on the process control block.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 3 of 9
Process States
State Diagram
The process, from its creation to completion, passes through various states. The
minimum number of states is five.
The names of the states are not standardized although the process may be in one of
the following states during execution.
1. New
A program which is going to be picked up by the OS into the main memory is called
a new process.
2. Ready
Whenever a process is created, it directly enters in the ready state, in which, it waits
for the CPU to be assigned. The OS picks the new processes from the secondary
memory and put all of them in the main memory.
The processes which are ready for the execution and reside in the main memory are
called ready state processes. There can be many processes present in the ready state.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 4 of 9
3. Running
One of the processes from the ready state will be chosen by the OS depending upon
the scheduling algorithm. Hence, if we have only one CPU in our system, the number
of running processes for a particular time will always be one. If we have n processors
in the system then we can have n processes running simultaneously.
4. Block or wait
From the Running state, a process can make the transition to the block or wait state
depending upon the scheduling algorithm or the intrinsic behavior of the process.
When a process waits for a certain resource to be assigned or for the input from the
user then the OS move this process to the block or wait state and assigns the CPU to
the other processes.
5. Completion or termination
When a process finishes its execution, it comes in the termination state. All the context
of the process (Process Control Block) will also be deleted the process will be
terminated by the Operating system.
6. Suspend ready
A process in the ready state, which is moved to secondary memory from the main
memory due to lack of the resources (mainly primary memory) is called in the
suspend ready state.
If the main memory is full and a higher priority process comes for the execution then
the OS have to make the room for the process in the main memory by throwing the
lower priority process out into the secondary memory. The suspend ready processes
remain in the secondary memory until the main memory gets available.
7. Suspend wait
Instead of removing the process from the ready queue, it's better to remove the
blocked process which is waiting for some resources in the main memory. Since it is
already waiting for some resource to get available hence it is better if it waits in the
secondary memory and make room for the higher priority process. These processes
complete their execution once the main memory gets available and their wait is
finished.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 5 of 9
2. Scheduling
Out of the many processes present in the ready queue, the Operating system chooses
one process and start executing it. Selecting the process which is to be executed next,
is known as scheduling.
3. Execution
Once the process is scheduled for the execution, the processor starts executing it.
Process may come to the blocked or wait state during the execution then in that case
the processor starts executing the other processes.
4. Deletion/killing
Once the purpose of the process gets over then the OS will kill the process. The Context
of the process (PCB) will be deleted and the process gets terminated by the Operating
system.
Process Queues
The Operating system manages various types of queues for each of the process states.
The PCB related to the process is also stored in the queue of the same state. If the
Process is moved from one state to another state then its PCB is also unlinked from
the corresponding queue and added to the other state queue in which the transition is
made.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 6 of 9
1. Job Queue
In starting, all the processes get stored in the job queue. It is maintained in the
secondary memory. The long term scheduler (Job scheduler) picks some of the jobs
and put them in the primary memory.
2. Ready Queue
Ready queue is maintained in primary memory. The short term scheduler picks the
job from the ready queue and dispatch to the CPU for the execution.
3. Waiting Queue
When the process needs some IO operation in order to complete its execution, OS
changes the state of the process from running to waiting. The context (PCB) associated
with the process gets stored on the waiting queue which will be used by the Processor
when the process finishes the IO.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 7 of 9
1. Arrival Time
The time at which the process enters into the ready queue is called the arrival time.
2. Burst Time
The total amount of time required by the CPU to execute the whole process is called
the Burst Time. This does not include the waiting time. It is confusing to calculate the
execution time for a process even before executing it hence the scheduling problems
based on the burst time cannot be implemented in reality.
3. Completion Time
The Time at which the process enters into the completion state or the time at which
the process completes its execution, is called completion time.
4. Turnaround time
The total amount of time spent by the process from its arrival to its completion, is
called Turnaround time.
5. Waiting Time
The Total amount of time for which the process waits for the CPU to be assigned is
called waiting time.
6. Response Time
The difference between the arrival time and the time at which the process first gets the
CPU is called Response Time.
CPU Scheduling
In the uniprogrammming systems like MS DOS, when a process waits for any I/O
operation to be done, the CPU remains idol. This is an overhead since it wastes the
time and causes the problem of starvation. However, In Multiprogramming systems,
the CPU doesn't remain idle during the waiting time of the Process and it starts
executing other processes. Operating System has to define which process the CPU will
be given.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 8 of 9
scheduling. The Operating System uses various scheduling algorithm to schedule the
processes.
This is a task of the short term scheduler to schedule the CPU for the number of
processes present in the Job Pool. Whenever the running process requests some IO
operation then the short term scheduler saves the current context of the process (also
called PCB) and changes its state from running to waiting. During the time, process is
in waiting state; the Short term scheduler picks another process from the ready queue
and assigns the CPU to this process. This procedure is called context switching.
If most of the running processes change their state from running to waiting then there
may always be a possibility of deadlock in the system. Hence to reduce this overhead,
the OS needs to schedule the jobs to get the optimal utilization of CPU and to avoid
the possibility to deadlock.
Scheduling Algorithms
There are various algorithms which are used by the Operating System to schedule the
processes on the processor in an efficient way.
There are the following algorithms which can be used to schedule the jobs.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong
Page 9 of 9
2. Round Robin
In the Round Robin scheduling algorithm, the OS defines a time quantum (slice). All
the processes will get executed in the cyclic way. Each of the process will get the CPU
for a small amount of time (called time quantum) and then get back to the ready queue
to wait for its next turn. It is a preemptive type of scheduling.
Prepared by
N. M. Istiak Chowdhury
Lecturer, Dept. of CSE
University of Chittagong