0% found this document useful (0 votes)
16 views9 pages

Process State

The document provides an overview of processes in operating systems, defining a process as an executing instance of a program and detailing its states, including new, ready, running, waiting, and terminated. It discusses process scheduling, highlighting the roles of long-term, short-term, and medium-term schedulers, and introduces the concept of process control blocks (PCBs) that store information about each process. Additionally, it outlines various CPU scheduling algorithms such as FCFS, SJF, priority scheduling, and round robin, explaining their mechanisms and providing examples.

Uploaded by

cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views9 pages

Process State

The document provides an overview of processes in operating systems, defining a process as an executing instance of a program and detailing its states, including new, ready, running, waiting, and terminated. It discusses process scheduling, highlighting the roles of long-term, short-term, and medium-term schedulers, and introduces the concept of process control blocks (PCBs) that store information about each process. Additionally, it outlines various CPU scheduling algorithms such as FCFS, SJF, priority scheduling, and round robin, explaining their mechanisms and providing examples.

Uploaded by

cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Process: A process or task is an instance of a program in execution.

The execution of a process


must programs in a sequential manner. At any time at most one instruction is executed. The
process includes the current activity as represented by the value of the program counter and the
content of the processors registers. Also it includes the process stack which contain temporary data
(such as method parameters return address and local variables) & a data section which contain
global variables.
Difference between process & program:
A program by itself is not a process. A program in execution is known as a process. A program is
a passive entity, such as the contents of a file stored on disk where as process is an active entity
with a program counter specifying the next instruction to execute and a set of associated resources
may be shared among several process with some scheduling algorithm being used to determinate
when the stop work on one process and service a different one.
Process state: As a process executes, it changes state. The state of a process is defined by the
correct activity of that process. Each process may be in one of the following states.
 New: The process is being created.
 Ready: The process is waiting to be assigned to a processor.
 Running: Instructions are being executed.
 Waiting: The process is waiting for some event to occur.
 Terminated: The process has finished execution.
Many processes may be in ready and waiting state at the same time. But only one process can be
running on any processor at any instant.
Process scheduling:

Scheduling is a fundamental function of OS. When a computer is multiprogrammed, it has


multiple processes completing for the CPU at the same time. If only one CPU is available, then a
choice has to be made regarding which process to execute next. This decision making process is
known as scheduling and the part of the OS that makes this choice is called a scheduler. The
algorithm it uses in making this choice is called scheduling algorithm.
Scheduling queues: As processes enter the system, they are put into a job queue. This queue
consists of all process in the system. The process that are residing in main memory and are ready
& waiting to execute or kept on a list called ready queue.
This queue is generally stored as a linked list. A ready queue header contains pointers to the
first & final PCB in the list. The PCB includes a pointer field that points to the next PCB in the
ready queue. The lists of processes waiting for a particular I/O device are kept on a list called
device queue. Each device has its own device queue. A new process is initially put in the ready
queue. It waits in the ready queue until it is selected for execution & is given the CPU.
SCHEDULERS:
A process migrates between the various scheduling queues throughout its life-time purposes. The
OS must select for scheduling processes from these queues in some fashion. This selection process
is carried out by the appropriate scheduler. In a batch system, more processes are submittedand
then executed immediately. So these processes are spooled to a mass storage device like disk,
where they are kept for later execution.
Types of schedulers:
There are 3 types of schedulers mainly used:
1. Long term scheduler: Long term scheduler selects process from the disk & loads them
into memory for execution. It controls the degreeof multi-programming i.e. no. of
processes in memory. It executes less frequently than other schedulers. If the degree of
multiprogramming is stable than the average rate of process creation is equal to the
average departure rate of processes leaving the system. So, the long term scheduler is
needed to be invoked only when a process leaves the system. Due to longer intervals
between executions it can afford to take more time to decide which process should be
selected for execution. Most processes in the CPU are either I/O bound or CPU bound.
An I/O bound process (an interactive ‘C’ program is one that spends most of its time in
I/O operation than it spends in doing I/O operation. A CPU bound process is one that
spends more of its time in doing computations than I/O operations (complex sorting
program). It is important that the long term scheduler should select a good mix of I/O
bound & CPU bound processes
2. Short - term scheduler: The short term scheduler selects among the process that are
ready to execute & allocates the CPU to one of them. The primary distinction between
these two schedulers is the frequency of their execution. The short-term scheduler must
select a new process for the CPU quite frequently. It must execute at least one in 100ms.
Due to the short duration of time between executions, it must be very fast.
3. Medium - term scheduler: some operating systems introduce an additional intermediate
level of scheduling known as medium - term scheduler. The main idea behind this
scheduler is that sometimes it is advantageous to remove processes from memory & thus
reduce the degree of multiprogramming. At some later time, the process can be
reintroduced into memory & its execution can be continued from where it had left off. This
is called as swapping. The process is swapped out & swapped in later by medium term
scheduler. Swapping is necessary to improve theprocess miss or due to some change in
memory requirements, the available memory limit is exceeded which requires some
memory to be freed up.

Process control block:

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.

CPU Scheduling Algorithm:


CPU Scheduling deals with the problem of deciding which of the processes in the ready queue is
to be allocated first to the CPU. There are four types of CPU scheduling that exist.
1. First Come, First Served Scheduling (FCFS) Algorithm:This is the simplest CPU
scheduling algorithm. In this scheme, the process which requests the CPU first, that is
allocated to the CPU first. The implementation of the FCFS algorithm is easily managed with a
FIFO queue. When a process enters the ready queue its PCB is linked onto the rear of the
queue. The average waiting time under FCFS policy is quiet long. Consider
the following example:
Process CPU time
P1 3
P2 5
P3 2
P4 4
Using FCFS algorithm find the average waiting time and average turnaround time if the order
is P1, P2, P3, P4.
Solution: If the process arrived in the order P1, P2, P3, P4 then according to the FCFS the Gantt
chart will be:
P1 P2 P3 P4
0 3 8 10 14
The waiting time for process P1 = 0, P2 = 3, P3 = 8, P4 = 10 then the turnaround time for
process P1 = 0 + 3 = 3, P2 = 3 + 5 = 8, P3 = 8 + 2 = 10, P4 = 10 + 4 =14.
Then average waiting time = (0 + 3 + 8 + 10)/4 = 21/4 =
5.25 Average turnaround time = (3 + 8 + 10 + 14)/4 = 35/4
= 8.75
The FCFS algorithm is non preemptive means once the CPU has been allocated to a process
then the process keeps the CP until the release the CPU either by terminating or requesting I/O.
2. Shortest Job First Scheduling (SJF) Algorithm: This algorithm associates with each
process if the CPU is available. This scheduling is also known as shortest next CPU burst,
because the scheduling is done by examining the length of the next CPU burst of the process
rather than its total length. Consider the following example:
Process CPU time
P1 3
P2 5
P3 2
P4 4
Solution:According to the SJF the Gantt chart will be
P3 P1 P2 P4
0 2 5 9 14

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

The average waiting time = (6 + 10 + 5 + 9)/4 = 7.

You might also like