You are on page 1of 25

Process Management

Content
 Recap: Process concepts, Process state lifecycle, PCB,
Scheduling Algos: FCFS, SJF
Process Scheduling Algorithms
Example of FCFS
Example of SJF
SRTF
Process Concept
An operating system executes a variety of programs that run as a process.

Process – a program in execution; process execution must progress in


sequential fashion. No parallel execution of instructions of a single
process
Multiple parts
◦ The program code, also called text section
◦ Current activity including program counter, processor registers
◦ Stack containing temporary data
◦ Function parameters, return addresses, local variables
◦ Data section containing global variables
◦ Heap containing memory dynamically allocated during run time
Process Concept (Cont.)
Program is passive entity stored on disk (executable file); process
is active

Program becomes process when an executable file is loaded into


memory
 Execution of program started via GUI mouse clicks, command
line entry of its name, etc.
One program can be several processes
◦Consider multiple users executing the same program
Process in Memory
Process State

As a process executes, it changes state


◦ New: The process is being created
◦ Running: Instructions are being executed
◦ Waiting: The process is waiting for some event to occur
◦ Ready: The process is waiting to be assigned to a processor
◦ Terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
Information associated with each process(also called task
control block)
Process state – running, waiting, etc.
Program counter – location of instruction to next execute
CPU registers – contents of all process-centric registers
CPU scheduling information- priorities, scheduling
queue pointers
Memory-management information – memory allocated
to the process
Accounting information – CPU used, clock time elapsed
since start, time limits
I/O status information – I/O devices allocated to process,
list of open files
CPU/Process Scheduling

CPU scheduling is the process of determining which process in the ready


queue is allocated to the CPU.

Various scheduling algorithms can be used to make this decision, such as


FirstCome-First-Served (FCFS), Shortest Job Next (SJN), Priority and Round
Robin (RR).

Different algorithm support different class of process and favor different


scheduling criterion.
Type of scheduling

Non-Pre-emptive: Under Non-Pre-emptive scheduling, once the CPU has


been allocated to a process, the process keeps the CPU until it releases the
CPU willingly.
A process will leave the CPU only
1. When a process completes its execution (Termination state)
2. When a process wants to perform some i/o operations(Blocked state)
Preemptive scheduling
Preemptive scheduling: once the CPU has been allocated to a process, A
process will leave the CPU willingly or it can be forced out. So, it will leave
the CPU
1. When a process completes its execution
2. When a process leaves CPU voluntarily to perform some i/o operations
3. If a new process enters in the ready states (new, waiting), in case of high
priority
4. When process switches from running to ready state because of time
quantum expire.
Scheduling Criteria

 CPU utilization – keep the CPU as busy as possible

 Throughput – # of processes that complete their execution per time unit

 Turnaround time – amount of time to execute a particular process


Turn around time = Completion time – Arrival Time
 Waiting time – amount of time a process has been waiting in the ready queue
Waiting time = Turn around time – Burst Time
Response time – amount of time it takes from when a request was submitted
until the first response is produced.
Response time = CPU first time – Arrival time
Scheduling Algorithm Optimization Criteria

 Max CPU utilization

Max throughput

Min turnaround time

Min waiting time

Min response time


First- Come, First-Served (FCFS) Scheduling

Criteria: Arrival Time


The mode is a non-preemptive algorithm (once the CPU has been allocated to a
process, the process keeps the CPU until it releases it either by terminating or by
switching to the waiting state.)
Process Arrival Time Burst Time Completion time TAT WT
P1 0 2 2 2 0
P2 1 2 4 3 1
P3 5 3 8 3 0
P4 6 4 12 6 2

TAT = CT- AT
WT = TAT- BT
First- Come, First-Served (FCFS) Scheduling

Criteria: Arrival Time


The mode is a non-preemptive algorithm (once the CPU has been allocated to a
process, the process keeps the CPU until it releases it either by terminating or by
switching to the waiting state.)

Process Burst Time


P1 24
P2 3
P3 3
 Suppose that the processes arrive in the order: P1 , P2 , P3
Example of FCFS Scheduling

Process Burst Time


P1 24
P2 3
P3 3
 The processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
P1 P2 P3
0 24 27 30

Waiting time for P1 = 0; P2 = 24; P3 = 27


Average waiting time: (0 + 24 + 27)/3 = 17
FCFS Scheduling Cont..

Suppose that the processes arrive in the order: P2 , P3 , P1


The Gantt chart for the schedule is:

P2 P3 P1
0 3 6 30

Waiting time for P1 = 6; P2 = 0; P3 = 3


Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case
Convoy effect - short process behind long process
Consider one CPU-bound and many I/O-bound processes
Shortest-Job-First (SJF) Scheduling

Criteria: Burst Time


The mode is a non-preemptive algorithm
Associate with each process the length of its next CPU burst
Use these lengths to schedule the process with the shortest time

SJF is optimal – gives minimum average waiting time for a given set of processes
SJF Scheduling Cont..

How do we determine the length of the next CPU burst?


Could ask the user
Estimate
Determining Length of Next CPU Burst

 Can only estimate the length – should be similar to the previous one
◦ Then pick process with shortest predicted next CPU burst

 Can be done by using the length of previous CPU bursts, using exponential
averaging
Example of SJF Scheduling

Process Burst Time


P1 6
P2 8
P3 7
P4 3
 SJF scheduling Gantt chart

P4 P1 P3 P2
0 3 9 16 24

 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7


Shortest Remaining Time First (SRTF) Scheduling

Preemptive version of SJF


Criteria: Burst Time
The mode is a preemptive algorithm

Whenever a new process arrives in the ready queue, the decision on which process
to schedule next is redone using the SJN algorithm.

Is SRTF more “optimal” than SJN in terms of the minimum average waiting time
for a given set of processes?
Example of SRTF Scheduling

Now we add the concepts of varying arrival times and preemption to the analysis
Process Arrival Time Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF (SRTF) Gantt Chart

P1 P2 P4 P1 P3
0 1 5 10 17 26

Average waiting time = [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6.5


Practice Example of SRTF Scheduling

Process Arrival Time Burst Time Completion time TAT WT RT


P1 0 5
P2 1 3
P3 2 4
P4 4 1
Upcoming topics

 Priority Based Scheduling


Round-Robin Scheduling

You might also like