0% found this document useful (0 votes)
2 views26 pages

Session2 Process Management

The document provides an overview of process management in operating systems, detailing definitions, states, and the five-state process model. It discusses context switching, deadlocks, prevention mechanisms, and various process scheduling algorithms including First-Come First-Served, Shortest-Job-First, Priority Scheduling, and Round-Robin. Additionally, it highlights the advantages and disadvantages of each scheduling method and offers references for further study.

Uploaded by

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

Session2 Process Management

The document provides an overview of process management in operating systems, detailing definitions, states, and the five-state process model. It discusses context switching, deadlocks, prevention mechanisms, and various process scheduling algorithms including First-Come First-Served, Shortest-Job-First, Priority Scheduling, and Round-Robin. Additionally, it highlights the advantages and disadvantages of each scheduling method and offers references for further study.

Uploaded by

Schoolboy LT
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DCIT 301

OPERATING SYSTEMS
SESSION 2
Process Management
Stephen A. Adingo
Dept of Computer Sci/Dept of Distance Educ.
Contact Information: saadingo@[Link]

College of Education
School of Continuing and Distance Education
Outline
2.1 Definition of a process and process state.

2.2 The five state process model.

2.3 Process context and context switching.

3.4 Deadlock and measures to prevent deadlock

3.5 Process Scheduling & Algorithms

Slide 2
Process and Process State
• Process: A process is basically a program in execution.
The execution of a process must progress in a sequential
fashion.

• The operating system is responsible for the following


activities in connection with process management:
– the creation and deletion of both user and system processes;
the scheduling of processes;
– and the provision of mechanisms for synchronization,
communication, and deadlock handling for processes.

Slide 3
Process and Process State
• Process state: As a process executes, it changes state. The
state of a process is defined in part by the current activity
of that process.

• Process, on the other hand, includes:


– Current value of Program Counter (PC)
– Contents of the processors registers
– Value of the variables
– The processes stack (SP) which typically contains temporary
data such as subroutine parameter, return address, and
temporary variables.
– A data section that contains global variables.

Slide 4
Five State Process Model

Slide 5
Five State Process Model

Slide 6
Process Control Block
• Each process is represented in the operating system
by a process control block PCS)—also called a task
control block.
Process state
process number
program counter
Registers
memory limits
list of open files
--------

Slide 7
Each Process may be in one of the
following states
• New State: The process being created.
• Running State: A process is said to be running if it
has the CPU, that is, process actually using the CPU
at that particular instant.
• Blocked (or waiting) State: A process is said to be
blocked if it is waiting for some event to happen
such as an I/O completion before it can proceed.
• Ready State: A process is said to be ready if it is
waiting to be assigned to a processor.
• Terminated state: The process has finished
execution.
Slide 8
Context switching?
• A context switch is the mechanism to store and
restore the state or context of a CPU in Process
Control block so that a process execution can be
resumed from the same point at a later time.

• Using this technique, a context switcher enables


multiple processes to share a single CPU.

• Context switching is an essential part of a


multitasking operating system features.
Slide 9
Deadlocks and deadlocks preventive
mechanisms
• A process requests resources; if the resources are
not available at that time, the process enters a wait
state.
• It may happen that waiting processes will never
again change state because the resources they
have requested are held by other waiting
processes.
• This situation is called a deadlock.

Slide 10
Deadlock Prevention
• By ensuring that at least one of these conditions cannot hold, we can
prevent the occurrence of a deadlock

• Mutual Exclusion – not required for sharable resources; must hold for
non-sharable resources.

• Hold and Wait – must guarantee that whenever a process requests a


resource, it does not hold any other resources.

• No Preemption – If a process that is holding some resources requests


another resource that cannot be immediately allocated to it, then all
resources currently being held are released.

• Circular Wait – impose a total ordering of all resource types, and require
that each process requests resources in an increasing order of
enumeration.

Slide 11
Dealing with deadlocks
• A process must request a resource before using it,
and must release the resource after using it.

• A process may request as many resources as it


requires to carry out its designated task.

• A process may utilize a resource in only the following


sequence in the diagram below

Slide 12
Dealing with deadlocks

Slide 13
What is a Process Scheduler
• 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.

Slide 14
Types of Scheduling
• Long-Term Scheduler: It is also called a job scheduler. A long-
term scheduler determines which programs are admitted to
the system for processing. It selects processes from the queue
and loads them into memory for execution.

• Short-Term Scheduler: It is also called a CPU scheduler. Its


main objective is to increase system performance in
accordance with the chosen set of criteria. It is the change of
ready state to running state of the process.

• Medium-Term Scheduler: The medium-term scheduler is in


charge of handling the swapped out-processes.
Slide 15
Scheduling Algorithms
• First-Come First-Served Scheduling: Jobs are executed on first come,
first served basis. It is a non-preemptive scheduling algorithm. Easy to
understand and implement. Its implementation is based on FIFO queue.

• Shortest-Job-First Scheduling: it executes jobs with the minimum CPU


time. It is a non-preemptive scheduling algorithm.

• Priority Scheduling: Each process is assigned a priority and the process


or job with the highest priority is executed first.

• Round-Robin Scheduling: This is preemptive scheduling algorithm. It


deals with a time quantum/time slice.
• Each process is executed within a time slice. If the time slice expires that
process is preempted for another process to have the CPU.

Slide 16
Implementation of the Scheduling
Algorithms
• First-Come, First-Served Scheduling
Process Burst Time
P1 24
P2 3
P3 3

Slide 17
First-Come, First-Served Scheduling
First-Come First-Served Algorithm

Waiting Time = Service


Process
Time – Arrival Time

P0 0–0=0

P1 5–1=4

P2 8–2=6

P3 16 – 3 = 13
Waiting time of each process:
Average Waiting Time
= (0+4+6+13) / 4
= 5.75

Slide 18
Shortest-Job-First Scheduling

Slide 19
Shortest-Job-First Scheduling

Arrival Execution Service


Process
Time Time Time
P0 0 5 0
P1 1 3 5
P2 2 8 14
Waiting time of each
P3 3 6 8
process:
Average Waiting Time
= (0 + 4 + 12 + 5)/4 = 21 / 4
Process
Waiting Time = Service = 5.25
Time – Arrival Time
P0 0–0=0
P1 5–1=4
P2 14 – 2 = 12
P3 8–3=5
Slide 20
Priority Scheduling

Slide 21
Priority Scheduling

Execution
Process Arrival Time Priority Service Time
Time
P0 0 5 1 0
P1 1 3 2 11
P2 2 8 1 14
P3 3 6 3 5

Waiting time of each process:


Process Waiting Time Average Waiting Time
P0 0–0=0 = (0 + 10 + 12 + 2)/4
P1 11 – 1 = 10 = 24 / 4
P2 14 – 2 = 12 =6
P3 5–3=2
Slide 22
Round-Robin Scheduling

Slide 23
Round-Robin Scheduling
Round Robin

Average Waiting Time


Waiting time of each process: = (9+2+12+11) / 4 = 8.5
Process Waiting Time
P0 (0 – 0) +(12 – 3) = 9
P1 (3 – 1) = 2
P2 (6 – 2) + (14 – 9) + (20 – 17) = 12
P3 (9 – 3) + (17 – 12) = 11

Slide 24
Evaluation of the scheduling
algorithms
• First come first served: A major disadvantage of this algorithm is that waiting
time can be large if processes with short requests wait behind long ones.

• Shortest job first: If the mechanism to determine what is the shortest job is faulty
then this might significantly reduce the throughput. Given a system with a lot of
short jobs and one long job then the long job might never be run.

• Priority scheduling: this scheduling may lead to starvation. Processes with low
priorities may never execute.

• Round robin scheduling: The parameter concerned with it is the time slice, which
has to be exactly the right size.
• If it was too short, there is a large overhead every time it expires and the context
switches, if it was too long, then we might end up with an unresponsive system.
Slide 25
References
• [Link]/~farrell/osf03/oldnotes/[Link]
• [Link]
als/computer_operating_system.htm
• Read Chapter 3 of Recommended Text – Williams
stalling, Operating Systems, 6th Edition.

• Visit this site to watch videos on the implementation of


the various scheduling algorithms-
[Link]
duling+algorithms
Slide 26

You might also like