Professional Documents
Culture Documents
1
The Journey
1 Computer 2 CPU, Memory 3 ISA 4 Computer
System System and Input
Performance
Output
6 Process 8 Operating
5 Operating System 7 Memory and File
System Design
Management Management
2
Definition
Process Management
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.
⚫ Reasons to create a new process
◦ New batch job
◦ New user logs on
◦ Created by O/S to provide a service
◦ E.g. Open Firefox and notice Task
Manager
4
Process Termination
• 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
⚫
Running - Instructions are being executed by processor.
3.
4. Waiting - The process is waiting for some event to occur (such
New Ready
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
There are two types of schedulers available :
1. Long Term Scheduler :
⚫ Long Term Schedulers decide which program must get into the job queue.
⚫ From the job queue, the Job Processor, selects processes and loads them into the memory for
execution.
⚫ Long term scheduler runs less frequently.
⚫ Primary aim of the Job Scheduler is to maintain a good degree of Multiprogramming. An
optimal degree of Multiprogramming means the average rate of process creation is equal to
the average departure rate of processes from the execution memory.
10
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 reintroduced into memory after some time and
its execution can be continued where it left off. This scheme is called
swapping.
11
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.
12
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).
14
Scheduling Algorithms
15
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.
16
FIFO
Waiting Time = Service Time - Arrival Time
Process Arrival Time Burst Time
P1 = 0-0=0
P1 0.0 7
P2 = 7-2=5
P2 2.0 4 P3 = 11-4=7
P3 4.0 1 P4 = 12-5=7
P4 5.0 4
Turn around Time = Burst Time + Waiting Time
P1 P2 P3 P4 P1 = 7+0=7
P2 = 4+5=9
0 7 11 12 16
P3 = 1+7=8
P4 = 4+7=11
18
SJF (non-preemptive)
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
0 7 8 12 16
P1 = 7+9=16
P1 P2 P3 P2 P4 P1 P2 = 4+1=5
P3 = 1+0=1
P4 = 4+2=6
0 2 4 5 7 11 16
(P1=5) ( P2=2) (P3=0) (P2=0) (P4=0) (P1=0)
21
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 CPU scheduler move along the queue
allocating the CPU to each process for a time
interval of upto 1 quantum. New processes are
added to the queue.
⚫ The algorithm’s performance heavily depends
upon the time quantum.
⚫ It works like FIFO if time quantum is large.