Unit 2
Unit 2
Process Management
Learning Objectives
• Process Concept
• States of a process
• Process Scheduling
• Context switching
• Creation of a Process
• Termination of a process
Learning Objectives (Conti..)
• Cooperating Processes
• Inter-process Communication
• Scheduling criterion
• Basics of scheduling algorithms
• Scheduling algorithms
• Multiprocessor and real-time scheduling
Process Concept
• Process – a program in execution.
• Process execution must progress in
sequential fashion.
• A process includes:
– program counter
– Text section
– Stack section
– data section
States of a Process
• As a process executes, it changes its 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.
State transitions of a process
Process Control Block
• The operating system maintains information
related to a process in a process control
block (PCB).
• This is also called as Task control block
Information in a PCB
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
Process Control Block
Process Scheduling
• Multiprogramming - more than one process
is in running state
• CPU is allocated in a time shared manner
• To schedule various processes - require a
set of queues.
• The processes are sent in to various queues
depending on the state of the process.
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.
Ready Queue And Various I/O
Device Queues
Representation of Process
Scheduling
Schedulers
• Long-term scheduler
– job scheduler
– selects which processes should be brought into
the ready queue.
• Short-term scheduler
– CPU scheduler
– selects which process should be executed next
and allocates CPU.
Addition of Medium Term
Scheduling
Types of Schedulers
• Short-term scheduler
– Is invoked very frequently (milliseconds)
– Must be fast
• Long-term scheduler
– Is invoked very infrequently (seconds, minutes)
– May be slow
• The long-term scheduler controls the degree
of multiprogramming.
Types of Processes
• I/O-bound process – spends more time
doing I/O than computations, many short
CPU bursts.
• CPU-bound process – spends more time
doing computations; few very long CPU
bursts.
Context Switch
• Save the state of the old process and load
the state for the new process.
• The context means the values of CPU
registers, process state and memory
management information.
• The speed of the context switch is also
depending on the hardware support
Operations on Processes
• Process Creation:
– Parent process create children processes, which, in turn
create other processes, forming a tree of processes.
– In UNIX fork system call creates new process
• Process Termination
Process Creation (Conti…)
• Resource sharing
– Parent and children share all resources.
– Children share subset of parent’s resources.
– Parent and child share no resources.
• Execution
– Parent and children execute concurrently.
– Parent waits until children terminate.
• Address space
– Child duplicate of parent.
– Child has a program loaded into it.
Process Termination
• Process executes last statement and asks the
operating system to decide it (exit).
– Output data from child to parent (using wait).
– Process’ resources are de-allocated by
operating system.
• A process can terminate another process
using abort system call.
Process Termination (Conti…)
P1 P2 P3
• Waiting time for P1 = 0; P2 = 24; P3 = 27
0
• Average waiting time: (0 + 24 24
+ 27)/327
= 17 30
FCFS Scheduling (Cont.)
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
Shortest-Job-First (SJR)
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:
– nonpreemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst.
– preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF).
• SJF is optimal – gives minimum average waiting time
for a given set of processes.
Priority Scheduling
• A priority number (integer) is associated
with each process
• The CPU is allocated to the process with the
highest priority (smallest integer highest
priority).
– Preemptive
– nonpreemptive
Priority Scheduling (Conti…)
• q large FIFO
• q small q must be large with respect to
context switch, otherwise overhead is too
high
Example of RR
Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
• The Gantt chart is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3