You are on page 1of 23

Process Management

TM2033 Platform Technology

By Dr. Faizan Qamar

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

9 Mobile Computing 10 Parallel Computing


Platform

2
Definition
Process Management

⚫ A process is a program in execution. A process needs certain resources, including


CPU time, memory, files, and I/O devices, to accomplish its task.
⚫ The operating system is responsible for the following activities in connection with
process management.
◦ Process creation and deletion
◦ Process suspension and resumption
◦ Provision of mechanisms for:
🞄🞄process synchronization
🞄🞄process communication

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

1. Swapping: O/S needs to release sufficient main memory to


bring in a process that is ready to execute.
2. Error: O/S may suspend a background process or it
suspects that process can cause an error.
3. Timing: Process exceed with periodic execution time.
4. Parent Process Request: To co-ordinate/ examine the
child processes, parents suspends child process.
5. Interactive user input: User wants to suspend the process for
debugging purpose.

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.

2. Short Term Scheduler :


⚫ This is also known as CPU Scheduler and runs very frequently.
⚫ The primary aim of this scheduler is to enhance CPU performance and increase process
execution rate.

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).

Turn around Time = Burst Time + Waiting Time


13
Scheduling Criteria Cont…
⚫ Waiting time - The sum of the periods spent waiting in the ready queue
amount of time a process has been waiting in the ready queue to acquire
get control on the CPU.
Waiting Time = Service Time - Arrival Time
⚫ Load average - It is the average number of processes residing in the
ready queue waiting for their turn to get into the CPU.
⚫ Response time - The amount of time it takes from when a request was
submitted until the first response is produced. Remember, it is the time till
the first response and not the completion of process execution(final
response).
⚫ In general CPU utilization and Throughput are maximized and other
factors are reduced for proper.

14
Scheduling Algorithms

Four major scheduling algorithms here which are


following :
⚫ First In First Out(FIFO) Scheduling
⚫ Shortest-Job-First(SJF) Scheduling
⚫ Priority Scheduling
⚫ Round Robin(RR) Scheduling

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

⚫ Average Waiting Time = (0 + 5 + 7 + 7)/4 = 4.75


⚫ Average Turnaround Time = (7+9+8+11)/4=8.75
17
Shortest-Job-First(SJF) Scheduling
⚫ Best approach to minimize waiting time.
⚫ Actual time taken by the process is already known to processor.
⚫ Difficult to implement.

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

⚫ Average waiting time = (0 + 3 + 6 + 7)/4 = 4


⚫ Average turnaround time=(7+4+10+11)/4= 8
19
SJF (preemptive)
Process Arrival Time Burst Time Waiting Time = Service Time - Arrival Time
P1 0.0 7 P1 = 9(11-2)-0=9
P2 = 3(7-4)-2=1
P2 2.0 4 P3 = 4-4=0
P4 = 7-5=2
P3 4.0 1
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
P4 = 4+2=6
0 2 4 5 7 11 16
(P1=5) ( P2=2) (P3=0) (P2=0) (P4=0) (P1=0)

• Average waiting time = (9 + 1 + 0 +2)/4 = 3


• Average turnaround time= (16+5+1+6)/4=7 20
Priority Scheduling
⚫ Priority is assigned for each process.
⚫ Process with highest priority is executed first and
so on.
⚫ Processes with same priority are executed in FIFO manner.
⚫ Priority can be decided based on memory requirements, time
requirements or any other resource requirement.

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.

Process Arrival Time Burst Time


P1 0.0 7 Time Quantum =2
Round Robin Flow Chart
P2 2.0 4
P1 P2 P1 P3 P2 P4 P1 P4 P1
P3 4.0 1
P4 5.0 4 0 2 4 6 7 9 11 13 15 16
(P1=5) (P2=2) (P1=3) (P3=0) (P2=0) (P4=2) (P1=1) (P4=0) (P1=0)
22
THANK YOU

You might also like