Understanding Process Management in OS
Understanding Process Management in OS
The O.S manages many kinds of activities ranging from user program to system programs like
spooler, print servers and proxy servers. Each of these activities is encapsulated in a process. A
process includes the complete execution context (code, data, program counters, register , and O.S
resources).
ACTIVITIES OF AN OPERATING SYSTEM IN REGARD TO PROCESS MANAGEMENT
1. Creation and deletion of user system process
2. Process synchronization
3. Process communication
4. Suspension and resumption of processes
5. Deadlock handling
A process is the unit of execution that has to follow a transition in execution.
MODEL OF A PROCESS CYCLE/PROCESS STATE
The process state consists of everything necessary used to resume a process execution.
A process state consists of at least the following
Code for the program
Program static data
Program dynamic data
Program procedure call stack
Program counter
i. Blocking
A process waiting for some event to occur before continuing execution. The event could
be input/output operation where blocked do not require the CPU services, since
execution can’t proceed until the blocking events completes.
ii. Ready
A process that is not allocated to the CPU but its ready to execute
iii. Running
A process that is executing in the CPU.
iv. Terminating /Exit
A process that has halted execution but a record of its process is still maintained by the
OS which is referred to as Zombie process or if a process has successfully completed.
PROCESS TRANSITION
i. Null-New
It moves from Null to new state when it is created to execute a program
ii. New-Ready
When O.S moves processes from secondary memory to main memory.
However, there is a limit of processes that the main memory can hold.
iii. Ready-Running
It moves from ready to running when an O.S selects it for an execution.
iv. Running-Exit
It moves from running to exit if it has successfully terminated or halted.
v. Running-Ready
Moves from running to ready if it is empty or timed out
vi. Running –Blocked
If it is waiting for a request
vii. Blocked-Ready
If the request it was waiting has occurred
NOTE-A process can move from ready to exit if it is terminated by parental
process or parental request.
REASONS FOR TERMINATION
i. Normal completion of a process
ii. Time limit exceeded i.e. if a process runs longer than specified
iii. Memory unavailable-A process can be terminated due to the two aspects:-
a. If an operating system cannot allocate a memory
b. If a process requires more memory than a system can provide.
iv. Bound violation-if a process tries to access memory allocation restricted
to it ,this will be terminated
v. Input/output failure-if mouse and keyboards are not functioning
vi. Arithmetic Errors-A process may try to perform illegal calculations e.g.
5/0
vii. Parental request-A parental process has authority to terminate any of its
offspring
viii. Operating system intervention-A process is terminated by O.S because of
some problems e.g. deadlock.
CHARACTERISTICS OF A SUSPENDED PROCESS
1. The process is not immediately available for execution
2. Process waiting for an event to occur
3. A suspended process placed in a suspended queue by an agent.
REASONS WHY A PROCESS MAY BE SUSPENDED
i. Swapping –This involves moving parts or all of the process from
main memory to disk
ii. Problematic process
iii. User request-It might be suspended for debugging
iv. Timing
v. Parental process request –A parent suspends a child process in
order to examine it.
PROCESS CONTROL BLOCK (PCB)/PROCESS DESCRIPTOR
It is a data block that describes the process to the O.S .With the PCB; the O.S can manipulate all
parts of the program state
The PCB is a data structure maintained by the O.S for every process. PCB is identified by an
integer process i.e. process ID
A PCB identifies a process by keeping all the information needed to keep track all the process
The architecture of a PCB is completely dependent on O.S and may contain different information
in different O.S
A STRUCTURE OF A PCB
Process ID-It is a unique identification for each of the process in the operating
system(O.S)
Process state – It is the current state of the process i.e. ready, running e.t.c.
Pointer – It is a pointer or an address of the next process
Priority (CPU scheduling information) – It refers to the process that requires the
CPU first
Program Counter – it is the address of the next instruction to be executed for this
process.
Program / CPU registers – Refers to various CPU registers where process need to
be stored for execution for running state.
I/O status information – It includes a list of I/O devices allocated to the process
PROCESS SCHEDULING/SCHEDULAR
In multiprocessing, scheduling is used to determine which process is given control of
the CPU. It is an O.S program that selects the next job to be admitted by the CPU.
It controls the order in which work is done and completed by the processor/CPU.
The process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a particular
strategy.
Process scheduling is an essential part of a Multiprogramming operating system. Such operating
systems allow more than one process to be loaded into the executable memory at a time and
loaded process shares the CPU using time multiplexing.
Scheduling Queues
Scheduling queues refers to queues of processes or devices. When the process enters into the
system, then this process is put into a job queue. This queue consists of all processes in the
system. The operating system also maintains other queues such as device queue. Device queue
is a queue for which multiple processes are waiting for a particular I/O device. Each device has
its own device queue.
This figure shows the queuing diagram of process scheduling.
Queue is represented by rectangular box.
The circles represent the resources that serve the queues.
The arrows indicate the process flow in the system.
Ready queue
Device queue
A newly arrived process is put in the ready queue. Processes waits in ready queue for allocating the
CPU. Once the CPU is assigned to a process, then that process will execute. While executing the
process, any one of the following events can occur.
The process could issue an I/O request and then it would be placed in an I/O queue.
The process could create new sub process and will wait for its termination.
The process could be removed forcibly from the CPU, as a result of interrupt and put back
in the ready queue.
1 Running
When new process is created by Operating System that process enters into the system
as in the running state.
2 Not Running
Processes that are not running are kept in queue, waiting for their turn to execute.
Each entry in the queue is a pointer to a particular process. Queue is implemented by
using linked list. Use of dispatcher is as follows. When a process is interrupted, that
process is transferred in the waiting queue. If the process has completed or aborted,
the process is discarded. In either case, the dispatcher then selects a process from the
queue to execute.
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
ROUND-ROBIN
It is an algorithm that selects the job that has been waiting the longest time i.e.
in this algorithm we assign equal CPU time. This is a pre-emptive scheduling
Interrupts from an interval timer ensures that processing is suspended and
control transferred to the scheduling algorithm at the conclusion of the time
quantum
Round robin is used extensively in time sharing system.
Each process is provided a fixed time to execute ,which is called
Quantum/Time slices.
In round robin, once a process is executed for a given time period, that process
is preempted and other process execute for a given time period
P0 (0-0) + (12-3) = 9
P1 (3-1) = 2
P3 (9-3) + (17-12) = 11
P0 3-0=3
P1 0-0=0
P2 16 - 2 = 14
P3 8-3=5
P1 6-1=5
P2 14 - 2 = 12
P3 0-0=0
Multi-level algorithm
The major disadvantages with the previous algorithms is that they basically
treat all jobs the same
Multi level queuing addresses this deficiency by customizing the scheduling of
a process based on the processes performance characteristics
This algorithm implements two or more scheduling queues i.e. (combination of
various algorithms together )
An entering process is inserted into the top level queue (high level).
Selected processes are allocating a time slices where upon expiration of a time
slice, the process is moved to the next lower queue.
If a process blocks before using its entire time slice, it is moved to the next
higher queue or to the top level queue.
If a process enters a high level queue, while a process of lower level queue is
executing, the low level queue may be pre-empted
PROCESS INTERRUPTS
An interrupt is a signal sent to the CPU by an external device typically I/O
devices.
This is an event that causes the CPU to temporarily transfer its control from
currently executing program to different programs
The interrupt requests the CPU to interrupt its current activities and attend to
the interrupting device needs
It is a signal sent to the CPU by an external device for any attention in need
The CPU responds to traps and interrupts by saving the current value of the
program counter and resetting it to a new address.
This allows the CPU to return to execution at point where it stopped before the
interrupt or trap occurred.
TYPES /CLASSES OF INTERRUPTS
i. Programmed interrupt
It is generalized by some conditions which occurs during program execution
e.g. division by zero, arithmetic overflow, trying to reference a location
outside a user allowed memory space.
ii. Timer interrupt
Generated by timer or clock within the processor. This allows the O.S to
perform certain functions on regular basis e.g. if a user downloading some
programs, there can be a timer interrupt if time elapses.
iii. Input/ output interrupt
Generated by I/O controller to signal normal completion of an operation or to
signal a variety of error condition.
iv. Hardware failure
It is caused by power failure i.e. catastrophic failure or brute force failure.
PURPOSE OF INTERRUPTS
1. To alert the O.S when a special event occurs so that it can suspend its activities
and deal with the situation
2. The interrupt improves the efficiency of computer system
DEADLOCK AND STARVATION
It is also called deadly embrace.
Deadlock occurs when two or more processes block waiting for an event to
occur which is under control of other blocked processes. E.g. a process A
sends messages to process B through one mail box and process B sends
message to process A through the second mail box.
Consider what happens if both processes attempt to read an incoming message
before they send a message, both will be in lock waiting.
For other processes to send a condition that can never be satisfied.
A deadlock is a permanent blocking of several processes that either compete
for a resource or communicate with each other.
CONDITIONS THAT CHARACTERIZE A DEADLOCK
The following conditions are necessary for a deadlock to occur.
1. Mutual exclusion
Each resource maybe allocated to any resource at any instant i.e. No resource can be
shared by more than one process at a time
2. Hold and wait
A process will not release previously granted resource while waiting for a pending
request to be granted. I.e. A process may hold a located resource while waiting
assignment of other resources.
3. Non- preemptive
No resource can be forcibly removed from a process holding it. i.e. A resource can not be
preempted until it is complete.
4. Circular wait
There exist a chain of two or more processes such that each process in the chain is
holding a resource requested by the next process in the chain.
COOPERATING PROCESSES
Cooperating process is a process that refers to two or more processes sharing some files in an
operating system. In cooperating process, independent process can not affect or be affected by
execution of another process
Advantages
Information sharing
Computational speed up
Modularity
Convenience
To avoid this effect of affecting each other, cooperating process uses the following approach:-
No two processes may be simultaneously inside their critical region or section
No process should have to wait forever to enter its critical section.
No process running outside of its critical section may block other processes.
In process cooperation there are two main systems call used in IPC namely.
Sleep
A sleep system call is called when a process is not permitted to access its critical section
It is a system call that causes a process to be suspended until any other process wakes it
up so it’s blocked.
Wake-up
If a process has been blocked will not be scheduled to run until another process uses the
wake-up system calls.
In most cases, wake-up is called by a process hen it leaves the critical section if any
other process has been blocked.
NOTE
On producer –consumer approach problem i.e. when a producer want to put a new
data in a buffer but the buffer is already full, the solution to this is that the producer goes
to sleep and wake-up when the consumer has removed the data.
REMOTE PRODURE CALL
It is a technique by which two processes on different machine interacts using procedure
calls/return syntax and semantics or rules.
In R.P.C, both the called and the calling process behave as if the process were running on
the same machine.
Reasons for R.P.C
o Ease of use
o Efficient and has a well defined interface