0% found this document useful (0 votes)
52 views

Process Management

The document discusses process management and CPU scheduling. It defines key concepts like processes, process states, process control blocks, context switching, and process scheduling queues. It describes long-term and short-term schedulers, and scheduling algorithms like first come first serve scheduling. Preemptive and non-preemptive scheduling are explained. Criteria for CPU scheduling like throughput, turnaround time and waiting time are also covered.

Uploaded by

topmotivezz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Process Management

The document discusses process management and CPU scheduling. It defines key concepts like processes, process states, process control blocks, context switching, and process scheduling queues. It describes long-term and short-term schedulers, and scheduling algorithms like first come first serve scheduling. Preemptive and non-preemptive scheduling are explained. Criteria for CPU scheduling like throughput, turnaround time and waiting time are also covered.

Uploaded by

topmotivezz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

MODULE II

PROCESS MANAGEMENT

1
Process
 Process is a program in Execution
 Process execution must progress in sequential
fashion.
 A process includes:
 program counter
 stack
 data section

2
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
process.
 terminated: The process has finished execution.

3
Diagram of Process State

4
Process Control Block (PCB)
Contains information associated with each process

5
Process Control Block (PCB)
Contains information associated with each process
 Process State - new, ready, running etc.
 Program Counter - address of next instruction to be
executed
 CPU registers - general purpose registers, stack pointer etc.
 CPU scheduling information (pointer) - process priority
 Memory Management information - base/limit information
 Accounting information - time limits, process number
 I/O Status information - list of I/O devices allocated

6
Switching From Process to Process

7
Schedulers
 Long-term scheduler (or job scheduler) – selects which
processes should be brought into the ready queue.
 Long-term scheduler is invoked very infrequently
(seconds, minutes)  (may be slow).

 Short-term scheduler (or CPU scheduler) – selects which


process should be executed next and allocates CPU.
 Short-term scheduler is invoked very frequently
(milliseconds)  (must be fast).

8
Schedulers

9
Long-term scheduler (or Job scheduler)
 Often, more processes are submitted than can be executed
immediately.
 These processes are spooled to a mass-storage device
(typically a disk), where they are kept for later execution.
 Job scheduler, selects processes from this pool and loads them
into memory for execution.

10
Short-term scheduler (or CPU scheduler)
 Whenever the CPU becomes idle, the operating system must
select one of the processes in the ready queue to be executed.
 The selection process is carried out by the short-term
scheduler, or CPU scheduler.
 The scheduler selects a process from the processes in memory
that are ready to execute and allocates the CPU to that
process.
 All the processes in the ready queue are lined up waiting for a
chance to run on the CPU. The records in the queues are
generally process control blocks (PCBs) of the processes.

11
Medium Term Scheduling
 A medium-term scheduler helps to remove a process from memory and
thus reduce the degree of multiprogramming.
 Later, the process can be reintroduced into memory, and its execution can
be continued where it left off. This scheme is called swapping.
 The process is swapped out, and is later swapped in, by the medium-term
scheduler.

12
Medium Term Scheduling

13
Medium Term Scheduling

14
Medium Term Scheduling

15
S.No. Preemptive Scheduling Non-Preemptive Scheduling
The CPU scheduling in which the resources (CPU Cycle) The type of scheduling in which
have been allocated to a process for a limited amount of once the resources (CPU Cycle)
time is known as preemptive scheduling. have been allocated to a process,
the process holds it until it
completes its burst time or
1. switches to the 'wait' state is
known as non-preemptive
scheduling.

In the preemptive scheduling, a process can be interrupted In the non-preemptive


when it is being executed. scheduling, a process cannot be
2. interrupted until it terminates
itself or its time is over.

If a process that has a high priority arrives frequently in the If a process that has a long burst
'ready' queue, the low priority processes may starve. time is running the CPU, then the
3. process that has less CPU burst
time would starve

4. It has overheads. It does not have overheads.

5. It is flexible in nature. It is not flexible in nature.

6. It is expensive. It is not expensive.


Examples − Round Robin scheduling, Shortest Remaining Examples − First Come First
7. Time First scheduling. Serve and Shortest Job 16
First.
Context Switch
 Switching the CPU to another process requires
performing a state save of the current process and
a state restore of a different process.
 This task is known as a context switch.
 When a context switch occurs, the kernel saves
the context of the old process in its PCB and loads
the saved context of the new process scheduled to
run.

17
CPU Scheduler
 When the CPU becomes idle, the operating system
selects one of the processes from the ready queue
to be executed.
 The selection process is carried out by the short-
term scheduler, or CPU scheduler.
 The scheduler selects a process from the processes
in memory that are ready to execute and allocates
the CPU to that process.

18
Process Scheduling Queues
 Job queue – set of all processes in the system.
 Ready queue – set of all processes residing in
main memory, ready and waiting to execute.
 Device queues – set of processes waiting for an
I/O device.
 Processes migrate between the various queues.

19
Preemptive & Non-preemptive Scheduling
 Non-preemptive Scheduling
 Once CPU has been allocated to a process, the
process keeps the CPU until
 Process exits OR
 Process switches to waiting state
 Preemptive Scheduling
 Process can be interrupted and must release the
CPU.
 Need to coordinate access to shared data

20
CPU Scheduling Decisions
 CPU scheduling decisions may take place when
a process:
 switches from running state to waiting state
 switches from running state to ready state
 switches from waiting to ready
 terminates
 Scheduling under 1 and 4 is non-preemptive.
 All other scheduling is preemptive.

21
Dispatcher
 Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler. This
involves:
 switching context
 switching to user mode
 jumping to the proper location in the user program to
restart that program
 Dispatch Latency:
 time it takes for the dispatcher to stop one process
and start another running.
 Dispatcher must be fast.

22
Scheduling Criteria
 CPU Utilization
 Keep the CPU and other resources as busy as possible
 Throughput
 No of processes that complete their execution per
time unit.
 Turnaround time
 amount of time to execute a particular process from
its entry time.

23
Scheduling Criteria (cont.)
 Waiting time
 amount of time a process has been waiting in the
ready queue.
 Response Time (in a time-sharing environment)
 amount of time it takes from when a request was
submitted until the first response is produced, NOT
output.

24
1. First Come First Serve (FCFS) Scheduling
 Process that requests the CPU FIRST is
allocated the CPU FIRST.
 FCFS is a non-preemptive algorithm.
 Implementation - using FIFO queues
 incoming process is added to the tail of the queue.
 Process selected for execution is taken from head of
queue.
 Performance metric - Average waiting time in
queue.
 Gantt Charts - are used to visualize schedules.
25
First-Come, First-Served(FCFS) Scheduling

 Example
 Suppose the arrival order for the processes is
 P1,
Process BurstP2, P3
Time
 Waiting time243
P1
P2
P3  P1 = 0; 3
 P2 = 24;
Gantt 
ChartP3
for = 27;
Schedule

 Average
P1 waiting time
P2 P3

0  (0+24+27)/324 = 27
17 30

26
FCFS Scheduling (cont.)

 Suppose the arrival


 Example order for the processes
Process Burst Time
is
P1 24  P2, P3, P1
P2 3  Waiting time
P3 3
 P1 = 6; P2 = 0; P3
= 3;
Gantt Chart for Schedule
 Average waiting time
P2 P3 P1  (6+0+3)/3 = 3 ,
better..
0 3 6 30

27
2. Shortest-Job-First(SJF) Scheduling
 Associate with each process the length of its next
CPU burst. Use these lengths to schedule the process
with the shortest time.
 Two Schemes:
 Scheme 1: Non-preemptive
 Once CPU is given to the process it cannot be preempted
until it completes its CPU burst.
 Scheme 2: Preemptive
 If a new CPU process arrives with CPU burst length less
than remaining time of current executing process,
preempt. Also called Shortest-Remaining-Time-First (SRTF).
 SJF is optimal - gives minimum average waiting time
for a given set of processes.
28
Non-Preemptive SJF Scheduling
Example
Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
Gantt Chart for Schedule

P1 P3 P2 P4

0 7 8 12 16
Average waiting time =
(0+6+3+7)/4 = 4

29
30
31
Preemptive SJF Scheduling(SRTF)
 Example
Process Arrival TimeBurst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
Gantt Chart for Schedule

P1 P2 P3 P2 P4 P1

0 2 4 5 7 11 16
Average waiting time =
(9+1+0+2)/4 = 3

32
33
34
35
3. Priority Scheduling
 A priority value (integer) is associated with each
process.
 The CPU is allocated to the process with the
highest priority.
 Equal-priority processes are scheduled in FCFS
order.

36
Priority Scheduling
 An SJF algorithm is simply a priority algorithm
where the priority (p) is the inverse of the
(predicted) next CPU burst. The larger the CPU
burst, the lower the priority, and vice versa.
 CPU is allocated to process with the highest
priority.
 Preemptive
 Nonpreemptive

37
Priority Scheduling (cont.)
 SJN is a priority scheme where the priority is
the predicted next CPU burst time.
 Problem
 Starvation/indefinite blocking - Low priority processes
may never execute.
 Solution
 Aging - as time progresses increase the priority of the
process.

38
Priority Scheduling (cont.)
Consider the following set of processes, assumed to
have arrived at time 0 in the order P1, P2, · · ·, P5,
with the length of the CPU burst given in
milliseconds:

Gantt chart
The average waiting time is 8.2 milliseconds.
39
4. Round Robin (RR)
 Each process gets a small unit of CPU time
 Time quantum usually 10-100 milliseconds.
 After this time has elapsed, the process is preempted and
added to the end of the ready queue.
 n processes, time quantum = q
 Each process gets 1/n CPU time in chunks of at most q time
units at a time.
 No process waits more than (n-1)q time units.
 Performance
 Time slice q too large - FIFO behavior
 Time slice q too small - Overhead of context switch is
too expensive.

40
Round Robin - Example
 Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
Gantt Chart for Schedule

P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162

Typically, higher average turnaround time than SRTF, but better response

41

You might also like