Process State
Process State
Each process is represented in the OS by a process control block. It is also by a process control
block. It is also known as task control block.
A process control block contains many pieces of information associated with a specific
process. It includes the following informations.
Process state: The state may be new, ready, running, waiting or terminated state.
Program counter:it indicates the address of the next instruction to be executed for this
purpose.
CPU registers: The registers vary in number & type depending on the computer
architecture. It includes accumulators, index registers, stack pointer & general purpose
registers, plus any condition- code information must be saved when an interrupt occurs
to allow the process to be continued correctly after- ward.
CPU scheduling information:This information includes process priority pointers to
scheduling queues & any other scheduling parameters.
Memory management information: This information may include such information
as the value of the bar & limit registers, the page tables or the segment tables,
depending upon the memory system used by the operating system.
Accounting information: This information includes the amount of CPU and real time
used, time limits, account number, job or process numbers and so on.
I/O Status Information: This information includes the list of I/O devices allocated to
this process, a list of open files and so on. The PCB simply serves as the repository for
any information that may vary from process to process.
The waiting time for process P1 = 0, P2 = 2, P3 = 5, P4 = 9 then the turnaround time for process
P3 = 0 + 2 = 2, P1 = 2 + 3 = 5, P4 = 5 + 4 = 9, P2 = 9 + 5 =14.
Then average waiting time = (0 + 2 + 5 + 9)/4 = 16/4 = 4
Average turnaround time = (2 + 5 + 9 + 14)/4 = 30/4 = 7.5
The SJF algorithm may be either preemptive or non preemptive algorithm. The preemptive SJF
is also known as shortest remaining time first.
Consider the following example.
Process Arrival Time CPU time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
In this case the Gantt chart will be
P1 P2 P4 P1 P3
0 1 5 10 17 26
The waiting time for
process P1 = 10 - 1 = 9
P2 = 1 – 1 = 0
P3 = 17 – 2 = 15
P4 = 5 – 3 = 2
The average waiting time = (9 + 0 + 15 + 2)/4 = 26/4 = 6.5
3. Priority Scheduling Algorithm: In this scheduling a priority is associated with each process
and the CPU is allocated to the process with the highest priority. Equal priority processes are
scheduled in FCFS manner. Consider the following example:
Process Arrival Time CPU time
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
According to the priority scheduling the Gantt chart will be
P2 P5 P1 P3 P4
0 1 6 16 18 19
The waiting time for
process P1 = 6
P2 = 0
P3 = 16
P4 = 18
P4 = 1
The average waiting time = (0 + 1 + 6 + 16 + 18)/5 = 41/5 = 8.2
4. Round Robin Scheduling Algorithm: This type of algorithm is designed only for the time
sharing system. It is similar to FCFS scheduling with preemption condition to switch between
processes. A small unit of time called quantum time or time slice is used to switch between the
processes. The average waiting time under the round robin policy is quiet long. Consider the
following example:
Process CPU time
P1 3
P2 5
P3 2
P4 4
Time Slice = 1 millisecond.
P1 P2 P3 P4 P1 P2 P3 P4 P1 P2 P4 P2 P4 P2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
The waiting time for process
P1 = 0 + (4 – 1) + (8 – 5) = 0 + 3 + 3 = 6
P2 = 1 + (5 – 2) + (9 – 6) + (11 – 10) + (12 – 11) + (13 – 12) = 1 + 3 + 3 + 1 + 1 + 1 = 10
P3 = 2 + (6 – 3) = 2 + 3 = 5
P4 = 3 + (7 – 4) + (10 – 8) + (12 – 11) = 3 + 3 + 2 + 1 = 9