Professional Documents
Culture Documents
Lecture # 6
Process Management
1
The Journey
1 Computer 2 CPU, Memory 3 ISA 4 Computer
System System and Input
Performance
Output
2
Definition
Process Management
⚫ The basic unit of software that the operating system deals with is … a
process.
⚫ A process is defined as a running program (It exists in memory, is
performing some action and can be controlled by a user, an
application or the operating system).
⚫ A process needs certain resources, including CPU time, memory, files,
and I/O devices, to accomplish its task.
⚫ A program is only regarded as a process when it is being executed.
Examples of processes are :
⚫ A game being played
⚫ MS Word running
⚫ Data being transmitted along a network
⚫ Antivirus software running
3
Creation of a process
⚫ When a new process is added,
O/S builds various data structures
to manage the newly added
process. It also allocate space to
the process in memory.
4
Process Termination Reasons
• Normal: Completion
• Time limit Exceeded: interactive process
• Memory Unavailable: limit on max no of processes
• Location Violation: access to memory location that is not allowed
• Protection Error: writing to read only file
• Arithmetic Error: divide by zero
• Time Overrun: waiting for I/O for infinite time
• I/O Failure: reading from line printer
• Invalid Instruction: branch to data area and trying to execute data
• Parent Termination
5
Process State diagram
Process State Possible Transitions
Processes can be any of the following states :
⚫
1. New - The process is being created but is not yet ready to execute.
2. Ready - The process is ready to execute and waiting to be Null New : New process is
assigned to a processor. created
⚫ New Ready
3. Running - Instructions are being executed by processor.
4. Waiting - The process is waiting for some event to occur (such
as an I/O completion or reception of a signal).
⚫ Ready Running (Dispatch)
5. Terminated - The process has finished execution will be destroyed by
the OS.
⚫ Running Terminated (Exit)
⚫ Running Ready (interrupt)
⚫ Running Waiting (I/O)
⚫ Waiting Ready
⚫ Ready Terminated (Running)
⚫ Waiting Terminated (Suspension)
6
Reasons for process suspension
7
Process Control Block (PCB)
There is a Process Control Block (PCB) for each process, enclosing
all the information about the process. It is a data structure, which
contains the following :
⚫ Process State - It can be running, waiting etc.
⚫ Process ID and parent process ID.
⚫ CPU registers and Program Counter. Program Counter
holds the address of the next instruction to be executed for
that process.
⚫ CPU Scheduling information - Such as priority information and
pointers to scheduling queues.
⚫ Memory Management information – E.g. page tables or
segment tables.
⚫ Accounting information - User and Kernel CPU time
consumed, account numbers, limits, etc.
⚫ I/O Status information -Devices allocated, open file
tables, etc.
8
CPU scheduling
⚫ CPU scheduling is a process which allows one process to use the CPU while the
execution of another process is on hold (in waiting state) due to unavailability of any
resource like I/O etc, thereby making full use of CPU.
⚫ Whenever the CPU becomes idle, the operating system must select one of the
processes in the ready queue to be executed.
⚫ The aim of CPU scheduling is to make the system efficient, fast and fair.
9
Types of Schedular
They are mainly responsible for selecting the jobs to be submitted into the system and deciding which
process to run.
1. Long-term Scheduler-
10
Types of Schedular
2. Short-term Scheduler-
3. Medium-term Scheduler-
The primary objective of medium-term scheduler is to perform swapping.
•Medium-term scheduler swaps-out the processes from main memory to secondary memory to free up
the main memory when required.
•After some time when main memory becomes available, medium-term scheduler swaps-in the
swapped-out process to the main memory and its execution is resumed from where it left off.
11
Process Scheduling
⚫ The act of determining which process in the ready state should be
moved to the running state is known as Process Scheduling.
⚫ For achieving this, the scheduler must apply appropriate rules for
swapping processes IN and OUT of CPU.
⚫ Some process can be re-introduced into memory after some time and
its execution can be continued where it left off.
12
Types of Process Scheduling
Schedulers fell into one of the two general categories :
Non pre-emptive scheduling :
⚫ Under non-preemptive scheduling, once the CPU has been allocated to a
process, the process keeps the CPU occupied until it releases the CPU
either by terminating or by switching to the waiting state.
Pre-emptive scheduling :
⚫ In this type of scheduling, the tasks are usually assigned with
priorities.
⚫ At times it is necessary to run a certain task that has a higher priority
before another task although it is running.
⚫ Therefore, the running task is interrupted for some time and resumed
later when the priority task has finished its execution.
13
Scheduling Criteria
There are many different criteria to check when considering the "best" scheduling
algorithm :
⚫ CPU utilization - To make out the best use of CPU and not to waste any CPU
cycle, CPU would be working most of the time(Ideally 100% of the time).
Considering a real system, CPU usage should range from 40% (lightly loaded) to
90% (heavily loaded.)
⚫ Throughput - It is the total number of processes completed per unit time or rather
say total amount of work done in a unit of time. This may range from 10/second to
1/hour depending on the specific processes.
⚫ Turnaround time- It is the amount of time taken to execute a particular process,
i.e., the interval from time of submission of the process to the time of completion
of the process(Wall clock time).
15
Scheduling Algorithms
16
First In First Out (FIFO) Scheduling
⚫ Also known as First Come First Serve(FCFS)
⚫ Jobs are executed on first come, first serve basis.
⚫ Easy to understand and implement.
⚫ Poor in performance as average wait time is high.
⚫ The main disadvantage of this algorithm is aging. Due to this problem, big jobs have to
wait for the CPU for a long time.
17
FIFO
Calculate Average Waiting Time and Average Turnaround Time
P1 P2 P3 P4 P1 = 7+0=7
P2 = 4+5=9
0 Service Time 7 11 12 16
P3 = 1+7=8
P4 = 4+7=11
19
SJF (non-preemptive)
Calculate Average Waiting Time and Average Turnaround Time
Waiting Time = Service Time - Arrival Time
Process Arrival Time Burst Time
P1 0.0 7 P1 = 0-0=0
P2 2.0 4 P3 = 7-4=3
P2 = 8-2=6
P3 4.0 1 P4 = 12-5=7
P4 5.0 4
Turn around Time = Burst Time + Waiting Time
P1 = 7+0=7
P1 P3 P2 P4 P3 = 1+3=4
P2 = 4+6=10
P4 = 4+7=11
Service Time 0 7 8 12 16
P4 5.0 4
Turn around Time = Burst Time + Waiting Time
P1 = 7+9=16
P1 P2 P3 P2 P4 P1
P2 = 4+1=5
P3 = 1+0=1
0 2 4 5 7 11 16 P4 = 4+2=6
(P1=5) ( P2=2) (P3=0) (P2=0) (P4=0) (P1=0)
22
Round Robin (RR)
⚫ This algorithm is especially implemented for time sharing systems.
⚫ It is similar to FIFO but preemption (Interrupt) is added to switch between
processes.
⚫ A small unit of time called as Time Quantum.
⚫ The algorithm’s performance heavily depends upon the time quantum.
⚫ It works like FIFO if time quantum is large.
23
THANK YOU