You are on page 1of 25

TOPIC 2

MEMORY AND PROCESS


MANAGEMENT
Part 2
LEARNING OUTCOME

At the end
• Describe the various process states
of this • Describe the life cycle of a process
chapter, • Describe the role of interrupt in process
management
students • Define the purpose of CPU scheduler
• Differentiate between preemptive and non-
will be able preemptive technique in scheduling.
to:
PROCESS STATES
• The state of a process is defined by the current activity of
that process.

• Each process may be in one of the following states:


• New - process is being created.
• Ready - process is waiting to be assigned to a processor.
• Waiting - process is waiting for some event to occur (such as
an I/O completion or reception of a signal).
• Running - instructions are being executed.
• Terminated - process has finished execution.
PROCESS STATES

This diagram shows the process states in


computing. You must memorize it.
PROCESS STATE: NEW

• Also called ‘created’.

• When a process is accepted, it requires the state “created”.

• In this situation, a process can:

 Wait in line with a 'ready‘ status.


 Retains and waiting to be treated because
of too many work entry.
PROCESS STATE: READY

• Process that has been in queue in main memory and


awaits the instructions of the CPU.

• In this situation, a process can:

 Get the CPU attention.


 Waiting to be served by the CPU.
PROCESS STATE: WAITING

• Also called ‘blocked’

• The process is waiting for some event to occur.

• It is a state from the RUNNING state when the OS is


not ready to perform as resource is not yet available.

• In this situation, a process can:

 Moved to a READY state when the event


for which it has been waiting occurs.
PROCESS STATE: RUNNING

• Also called 'active' or 'executing'.

• Running process is being executed in the CPU.

• In this situation, a process can:

 Declare the process was completed and


terminate.
 Blocked because the required resources are
not yet available.
PROCESS STATE: TERMINATED

• A process can be removed / terminated from the


running state before or after work is completed.

• In both the cases:

 The process will be eliminated.


 All the resources of the process-including
memory, open files, and I/0 buffers-are
de-allocated by the operating system.
PROCESS LIFE CYCLE

During a life-cycle, there


are only three states.
Blocked
Running
Ready
‘New’ and ‘Terminated’ are
not part of a running
process.
Interrupts

An interrupt is a signal from a device or a


program within the computer.

Interrupt causes the operating system to stop


for a while and figure out what to do next
based on the interrupt’s request.

Usually happens when there are high-priority


processes incoming.
Cont..

Imagine interrupt as if some part of the computer suddenly raised


its hand to ask for the CPU's attention in a busy environment
CPU Scheduler
I must schedule all
these to prevent
conflicts
Cont..

CPU scheduler resides in the CPU.

There are 3 types of CPU scheduler:


1. Short Term Scheduler
2. Medium Term Scheduler
3. Long Term Scheduler
Medium
Short Term Long Term
Term
Scheduler Scheduler
Scheduler
Is a process swapping
Is a CPU scheduler Is a job scheduler
scheduler

It can re-introduce the


It selects processes from
It selects processes which process into memory and
pool and loads them into
are ready to execute execution can be
memory for execution
continued

Speed is in between short Speed is lesser than short


Speed is fastest
and long term term scheduler
Short? Medium?
Answer

Short term scheduler

Medium term
scheduler
Short? Medium? Long?
Answer

Long term
scheduler

Short term
scheduler

Medium term
scheduler
More..?

B
C
A

B
C

A Long term scheduler


B Short term scheduler
C Medium term scheduler
Preemptive and Non-Preemptive

Non-preemptive scheduling technique


• In non-preemptive scheduling, once the CPU is allocated to a
process, the process holds (retains) the CPU until it completes
• Example: FIFO scheduling algorithm

Preemptive scheduling technique


• In Preemptive scheduling, the scheduler may suspend/postpone
the execution of a process, in order to allocate the CPU to
another process
• Example: Priority scheduling algorithm

Preempt = take over, occupy


Arrival
Process Burst time
time Process Table
P1 0 10
P2 5 3

Gantt Chart
P1 P2
time
t=5
t=0 t=10 t=13
At t=5, P2 arrives
but has to wait

FIFO scenario:
- P1 arrives at t=0, while P2 arrives at t=5.
- Hence P1 will execute first
Turnaround
Process Burst time Priority Finish Time Waiting Time Response Time
Time
P1 10 3 16 6 16 16
P2 1 1 1 0 1 1
P3 2 3 18 16 18 18
P4 1 4 19 18 19 19
P5 5 2 6 1 6 6

• PRIORITY scenario:
- P2 has the highest priority, so it executes first. P2 preempts
P1.
Q&A

You might also like