Chapter-2 Process Management

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CHAPTER – 2 PROCESS MANAGEMENT

Process
A process is a program in execution. The execution of a process must progress in a sequential
fashion. Definition of process is following.

A process is defined as an entity which represents the basic unit of work to be implemented in
the system.

Components of process are following.

S.N. Component & Description


Object Program
1
Code to be executed.
Data
2
Data to be used for executing the program.
Resources
3
While executing the program, it may require some resources.
Status
Verifies the status of the process execution.A process can run to
4 completion only when all requested resources have been allocated to
the process. Two or more processes could be executing the same
program, each using their own data and resources.

Program
A program by itself is not a process. It is a static entity made up of program statement while process
is a dynamic entity. Program contains the instructions to be executed by processor.

A program takes a space at single place in main memory and continues to stay there. A program
does not perform any action by itself.

Process States
As a process executes, it changes state. The state of a process is defined as the current activity of
the process.

Process can have one of the following five states at a time.


S.N. State & Description
New
1
The process is being created.
Ready
The process is waiting to be assigned to a processor. Ready processes
2
are waiting to have the processor allocated to them by the operating
system so that they can run.
Running
3 Process instructions are being executed (i.e. The process that is
currently being executed).
Waiting
4 The process is waiting for some event to occur (such as the completion
of an I/O operation).
Terminated
5
The process has finished execution.

Process Control Block (PCB)


Each process is represented in the operating system by a process control block (PCB) also called a
task control block. PCB is the data structure used by the operating system. Operating system groups
all information that needs about particular process.

PCB contains many pieces of information associated with a specific process which are described
below.

S.N. Information & Description


Pointer
1 Pointer points to another process control block. Pointer is used for
maintaining the scheduling list.
Process State
2
Process state may be new, ready, running, waiting and so on.
Program Counter
3 Program Counter indicates the address of the next instruction to be
executed for this process.
CPU registers
CPU registers include general purpose register, stack pointers, index
4
registers and accumulators etc. number of register and type of register
totally depends upon the computer architecture.
Memory management information
This information may include the value of base and limit registers, the
5 page tables, or the segment tables depending on the memory system
used by the operating system. This information is useful for deallocating
the memory when the process terminates.
Accounting information
6 This information includes the amount of CPU and real time used, time
limits, job or process numbers, account numbers etc.

Process control block includes CPU scheduling, I/O resource management, file management
information etc.. The PCB serves as the repository for any information which can vary from process to
process.Loader/linker sets flags and registers when a process is created. If that process get
suspended, the contents of the registers are saved on a stack and the pointer to the particular stack
frame is stored in the PCB. By this technique, the hardware state can be restored so that the process
can be scheduled to run again.
Process Scheduling
 FCFS (First Come First Served) Scheduling
The FCFS scheduler simply executes processes to completion in the order they are
submitted. We will implement FCFS using a queue data structure. Given a group of process to
run, insert them all into the queue and execute them in that order.
This is the one of the simplest scheduling in the order of their arrival. it implementation
is just like FIFO.

Process Duration Order Arrival Time


P1 24 1 0
P2 3 2 0
P3 4 3 0
The final schedule (Gantt chart):

P1(24) P2(3) P3(4)

0 24 27 31

P1 waiting time: 0 The average waiting time:


P2 waiting time: 24 (0+24+27)/3 = 17
P3 waiting time: 27

 Jobs are executed on first come, first serve basis.


 Easy to understand and implement.
 Poor in performance as average wait time is high.

Wait time of each process is following

Process Wait Time : Service Time - Arrival Time


P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13

Average Wait Time: (0+4+6+13) / 4 = 5.55

 Shortest Job Next (SJN) Scheduling


Shortest Job Next may be implemented in either non-preemptive or preemptive.SJN
scheduling is an optimal scheduling in terms of minimizing the average waiting time of a given
set of process.
The SJN scheduler is exactly like FCFS except that instead that instead of choosing the
job at the front of the queue, it will always choose the shortest Job available. We will use a
shorted list to order the processes from longest to shortest. When adding a new process/stack,
we need to figure out where in the list to insert it.
Example :

Process Duration Order Arrival Time


P1 10 1 0
P2 2 2 2
P1(2)
P2(2) P1(8)

0 2 4 12

P1 waiting time: 4-2 =2 The average waiting time (AWT):


P2 waiting time: 0 (0+2)/2 = 1

 Round Robin Scheduling


This is one of the oldest, simplest and widely used scheduling. The round robin
Scheduling is primarily used in a time sharing and multiuser system where the primary
requirement is to provide reasonably good response time and in general to share the system
fairly among all user.
Basically the CPU time time is divided into time slices. Each process is allocated a small
time slice while it is running. No process can run for more then one time slice when there are
others waiting for others.
Example :

Process Duration Order Arrival Time


P1 3 1 0
P2 4 2 0
P3 3 3 0
Suppose time quantum is: 1 unit, P1, P2 & P3 never block

Do it yourself

P1 P2 P3 P1 P2 P3 P1 P2 P3 P2

0 10

P1 waiting time: 4 The average waiting time (AWT):


P2 waiting time: 6 (4+6+6)/3 = 5.33
P3 waiting time: 6

 Priority Base Non Preemptive


In this type of scheduling, each process is allocated a priority level. Depanding on the
priority level, the OS can run a process of high priority.the OS may remove a low priority
process in RUNNING state, in order to allow a highly priority process to run.
With the preemptive scheduling, a running process may be replaced by a higher priority
process at any time. If higher priority process has changed state from being dormant or
suspended to ready state, the scheduler will choose this process to be the next process to run.

 Priority Base Preemptive


In this type of scheduling, each process continues to run till it terminates or requires an
Input/Output or some synchronization signal.
In non-preemptive scheduling, once scheduled, a selected job runs till it is completed.
the running process retains ownership of allocated resources, including the processor,until it
voluntarily surrenders control to OS.

You might also like