CHAPTER 2
PROCESS
MANAGEMENT
LJ Polytechnic
Process Management
outline
Process
Process Life Cycle
Scheduling and Scheduler
Inter process communication
Process Synchronization
Deadlock
LJ Polytechnic
Process Management
Process
Process
• Process is an instance of an executing
program.
• Process is a active entity as it is created
during execution and loaded into the main
memory.
• Process exists for a limited span of time as it
gets terminated after the completion of task.
• Process is a dynamic entity.
• Process has a high resource requirement, it
needs resources like CPU, memory address,
I/O during its lifetime. LJ Polytechnic
Process Management
Process life Cycle
Process Life Cycle
LJ Polytechnic
Process Management
Process life Cycle
1. New
• When a process is first create, it occupies
‘New’ state. In this state process awaits to
enter in Ready state.
2. Ready
• New -> Ready to run. After the creation of a
process, the process enters the ready state
i.e. the process is loaded into the main
memory.
• The process here is ready to run and is
waiting to get the CPU time for its execution.
Processes that are ready for execution by
LJ Polytechnic
Process Management
Process
3. Run
• The process is chosen by CPU for execution
and the instructions within the process are
executed by any one of the available CPU
cores.
4. Waiting
• Whenever the process requests access to I/O
or needs input from the user or needs access
to a critical region(the lock for which is
already acquired) it enters the blocked or
wait state.
• The process continues to wait in the main
memory and does not require CPU.
• Once the I/O operation is completed the
LJ Polytechnic
Process Management
Process life Cycle
5. Terminated
• Process is killed as well as PCB is deleted. A
process can terminated by completing its
execution.
LJ Polytechnic
Process Management
Scheduler
There are three types of scheduler
1. Long term scheduler
2. Medium term scheduler
3. Short term scheduler
LJ Polytechnic
Process Management
Scheduler
1. Long term scheduler
It is a first level scheduler.
It can be found in operating systems where
there is support for ‘batch’, like as batch
operating system.
It works with the batch queue.
It selects the next batch job/ process to be
executed. Such process is loaded in main
memory and waits in ready state for CPU to
become free.
It executes much less frequently compared
to other schedulers.
It controls the degree of multi programming,
i.e. the total number of processes residing in
LJ Polytechnic
Process Management
Scheduler
2. Medium-term scheduler:
It is a second level scheduler.
It can be found in operating systems where
there is support for swapping.
It swaps-in and swap-out processes between
main memory and disk.
It also controls the degree of multi
programming i.e. the total number of
processes residing in the main memory.
LJ Polytechnic
Process Management
Scheduler
3. Short term scheduler:
It is a third level scheduler.
It can be found always in all modern
operating Systems.
It works with the ready queue.
It selects the next process to be executed by
CPU whenever more than one process is
simultaneously in the Ready state.
It controls the Ready-to-Running state
transitions in process life cycle.
It execute much frequently compared to
other scheduler.
LJ Polytechnic
Process Management
Inter Process Communication
Inter process communication is the
mechanism provided by the operating
system that allows processes to
communicate with each other.
This communication could involve a process
letting another process know that some
event has occurred or the transferring of
data from one process to another.
Process 1 Process 2
LJ Polytechnic
Process Management
Inter Process Communication
Examples:
A shell pipeline in UNIX
Printing on printer in Network
Chat or Mail Server
Issues related to IPC:
How one process can pass information
to other processes
Two or more processes should not get
into each others way
Proper sequencing should be
LJ Polytechnic
Process Management
Inter Process Communication
Independent process
This process does not communicate
with any other process in the system.
Co-operating process
This process communicates with other
process in the system.
LJ Polytechnic
Process Management
Inter Process Communication
Advantages of Co-operating
process:
Information Sharing
Computation Speedup
Modularity
Convenience
Disadvantages of Co-operating
process:
They give rise to problems such as
race conditions. LJ Polytechnic
Process Management
Race Condition
A race condition is a situation where two or
more processes are reading or writing some
shared data and the final result depends on
the relative order of their execution, is called
race condition or racing problem.
Example: Suppose process P0 and P1 are
accessing common integer variable ‘A’ and
Process
initial P0:of A=1000 Process P1:
value
Read (A); Read (A);
A: A-100; A: A+200;
Write (A); Write (A);
LJ Polytechnic
Process Management
Race Condition
Possibility 1:
Process P0: Process P1:
Read (A); ----
---- Read (A);
A: A-100; ----
Write (A); ----
---- A: A+200;
---- Write (A);
LJ Polytechnic
Process Management
Race Condition
Possibility 2:
Process P0: Process P1:
Read (A); ----
---- Read (A);
---- A: A+200;
---- Write (A);
A: A-100; ----
Write (A); ----
LJ Polytechnic
Process Management
Mutual Exclusion & Critical Section
A code segment of a process where the
shared resource is accessed, is referred as
critical section.
Mutual Exclusion is the way of making sure
that if one process is executing critical
section, other processes will be excluded
from executing critical section.
LJ Polytechnic
Process Management
Mutual Exclusion & Critical Section
LJ Polytechnic
Process Management
Mutual Exclusion & Critical Section
General Structure of a Critical Section
Solution:
LJ Polytechnic
Process Management
Semaphores
A semaphore is an integer variable that, apart
from initialization, is accessed only through two
standard atomic operations: Down (Wait) and Up
(Signal).
wait: The wait operation decrements the value of
its argument S, if it is positive. If S is negative or
wait(S)
zero, then no operation is performed.
{ while (S<=0);
S--;
}
LJ Polytechnic
Process Management
Semaphores
Signal: The signal operation increments the value
of its argument S.
signal(S)
{
S++;
}
Types of Semaphore:
Binary Semaphore
Counting Semaphore
LJ Polytechnic
Process Management
Deadlock
A set of processes is deadlocked, if each
process in the set is waiting for an event
that only another process in the set can
cause.
This event can be caused by some other
process from the set. But none of them will
cause any event, because all are waiting in
waiting state.
Mutual Exclusion:- Each resource can be
assigned to exactly one process. If any
process requests resource which is not free,
then that process will wait until resource
become free.
Hold and wait:-A process must be holding at
LJ Polytechnic
Thank You
LJ Polytechnic