0% found this document useful (0 votes)
75 views45 pages

Lecture 2 - Process Management Part 2 Process States

The document discusses process states and scheduling. It provides 6 key process states: new, ready, running, blocked/waiting, terminated, and suspended ready/wait. It then discusses the transitions between these states and explanations for each state. The document also discusses process scheduling concepts including the process scheduler, scheduling queues, types of processes, and the different levels of scheduling including long-term, medium-term, and short-term schedulers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views45 pages

Lecture 2 - Process Management Part 2 Process States

The document discusses process states and scheduling. It provides 6 key process states: new, ready, running, blocked/waiting, terminated, and suspended ready/wait. It then discusses the transitions between these states and explanations for each state. The document also discusses process scheduling concepts including the process scheduler, scheduling queues, types of processes, and the different levels of scheduling including long-term, medium-term, and short-term schedulers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Process States

2
3 1

Blocked

• Possible process states


• running
• blocked
• ready
• Transitions between states shown 1
Process 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
processor
• terminated: The process has finished execution
Process States
1. New
• A program which is going to be picked up by the OS into the main memory
is called a new process.
2. Ready
• Whenever a process is created, it directly enters in the ready state, in
which, it waits for the CPU to be assigned.
• The OS picks the new processes from the secondary memory and put all of
them in the main memory.
• The processes which are ready for the execution and reside in the main
memory are called ready state processes.
• There can be many processes present in the ready state.
Process States
3. Running
• One of the processes from the ready state will be chosen by the OS
depending upon the scheduling algorithm.
• Hence, if we have only one CPU in our system, the number of running
processes for a particular time will always be one.
• If we have n processors in the system then we can have n processes
running simultaneously.
Process States
4. Block or wait
• From the Running state, a process can make the transition to the
block or wait state depending upon the scheduling algorithm or the
intrinsic behavior of the process.
• When a process waits for a certain resource to be assigned or for the
input from the user then the OS move this process to the block or
wait state and assigns the CPU to the other processes.
5. Completion or termination
• When a process finishes its execution, it comes in the termination
state.
• All the context of the process (Process Control Block) will also be
deleted the process will be terminated by the Operating system.
Process States
5. Suspend wait
• Instead of removing the process from the ready queue, it's better to
remove the blocked process which is waiting for some resources in
the main memory.
• Since it is already waiting for some resource to get available hence it
is better if it waits in the secondary memory and make room for the
higher priority process.
• These processes complete their execution once the main memory
gets available and their wait is finished.
6. Suspend Ready
• A process in the ready state, which is moved to secondary memory
from the main memory due to lack of the resources (mainly primary
memory) is called in the suspend ready state.
• If the main memory is full and a higher priority process comes for the
execution then the OS have to make the room for the process in the
main memory by throwing the lower priority process out into the
secondary memory.
• The suspend ready processes remain in the secondary memory until
the main memory gets available.
Process Scheduler

• Lowest layer of process-structured OS


• handles interrupts, scheduling
• Above that layer are sequential processes
9
Scheduling Concepts
• Process scheduling is an essential part of a
Multiprogramming operating systems.

• The process scheduling is the activity of the


process manager that handles:
• The removal of the running process from the CPU and
• The selection of another process on the basis of a
particular strategy.

10
CPU Switch From Process to Process
Process Control Block (PCB)
• Each process is represented in a operating system by a Process
Control Block (PCB) which has following information:

• Process state
• Program counter (PC)
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
Implementation of Process Context

Fields of a Process Table/ PCB entry


13
Process/Thread Context
Process context is process’s current state(what is in its registers).

Right Operand
Left Operand Status
Registers
R1
R2
...
Rn
Functional Unit
Result ALU

PC
IR
Ctl Unit
Context Switching
• Context Switching: We need to save the context of the current running process so it can be resumed af
the interrupt is handled.

15
Context Switching
Old Process/Thread
Descriptor(PCB)

CPU

New Process/Thread
Descriptor(PCB)
Process Scheduling Queues
• The OS maintains all PCBs in Process
Scheduling Queues.
• The OS maintains a separate queue for each
of the process states and PCBs of all
processes in the same execution state are
placed in the same queue.
• When the state of a process is changed, its PCB
is unlinked from its current queue and moved to
its new state queue.

17
Implementation of Processes

Skeleton of what lowest level of OS does when an


interrupt occurs

18
Process Scheduling
• As processes enters the system, they are put into
Job queue
• The processes that are stay in main memory and are ready and
waiting to execute are kept on a list called Ready queue
• A ready queue contains pointers to the first and final PCBs in the list
• The list of processes waiting for a particular I/O is called a Device
queue
Ready Queue And Various I/O Device Queues

Printer
1

Printer
2
Queueing Diagram
A new process is initially put in the ready queue, once the process is
located in CPU, one of several events may occur:
• The process issue a I/O request, and then be placed in I/O queue
• The process create a new subprogram and wait for the sub process’
termination
• The process could be removed from CPU and be placed back to ready
queue
Queueing Diagram
Types of Processes
Processes can be described as either:
• 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
Types of Processes

• Bursts of CPU usage alternate with periods of I/O wait


a) a CPU-bound process
b) an I/O bound process

24
Model of Process Execution

Preemption or voluntary yield

New Ready Scheduler Done


CPU
Process List job
job
job “Running”
“Ready”
Resource
Allocate Manager Request
job
job
“Blocked”
Resources
Schedulers
• Long-term scheduler (or job scheduler)

• Selects which processes should be brought into the ready


queue.
• It determines which jobs or processes may compete for
system resources.
• The main objective of the job scheduler is to provide the
medium-term scheduler with an appropriate number of
jobs.
• Issues with too few jobs and too many jobs…..
Schedulers

• Medium-term scheduler (or Swapper)


• Swaps processes in and out of memory.
• Any memory management system that supports
multiprogramming can use swapping to allow
more processes to share a system that can
physically fit in memory.
Addition of Medium Term Scheduling
Medium-term scheduler
• Sometimes it can be advantage to remove process from memory and
thus decrease the degree of multiprogrammimg
• This scheme is called swapping
Schedulers

• Short-term scheduler (or CPU scheduler or


dispatcher)
• Selects which process that is loaded in the main
memory and ready to run should be executed next
and allocates CPU.
• It can be two level scheduling: Thread Scheduling
within Process Scheduling
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
Comparison among Scheduler
S.N. Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

1 It is a job scheduler It is a CPU scheduler It is a process swapping


scheduler.
2 Speed is lesser than Speed is fastest among Speed is in between both
short term scheduler other two short and long term
scheduler.
3 It controls the degree of It provides lesser control It reduces the degree of
multiprogramming over degree of multiprogramming.
multiprogramming
4 It is almost absent or It is also minimal in time It is a part of Time
minimal in time sharing sharing system sharing systems.
system
5 It selects processes from It selects those It can re-introduce the
pool and loads them processes which are process into memory
into memory for ready to execute and execution can be
execution continued. 32
Schedulers
• On some systems, the long-term scheduler maybe
absent or minimal
• Just simply put every new process in memory for
short-term scheduler
Scheduling Algorithm Goals

34
Scheduling Criteria / Goals
1. CPU Utilization:
• the percentage of time the CPU is executing a process.
• The load on the system affects the level of utilization
that can be achieved;
• High Utilization – is more easily achieved on more heavily
loaded systems
• For example: on a single-user system, CPU utilization is
relatively unimportant where as on a large, expensive,
time-shared system, it may be the primary
consideration.

35
Scheduling Criteria / Goals
2. Balanced Utilization:
• The percentage of time all resources are utilized.
• Instead of just evaluating CPU utilization, utilization of
memory, I/O devices, and other system resources are also
considered.

36
Scheduling Criteria / Goals
3. Throughput:
• The number of processes the system can execute in a
period of time.
• The average length of the processes must be
considered in calculation of Throughput.
• For Example: on a system with long processes, the
throughput will be less as compared with systems with
short processes.

37
Scheduling Criteria / Goals
4. Turnaround Time:
• The average period of time it takes a process to
execute.
• It includes all the time that a process spends in the
system.
• It is computed by the subtracting the time the process
was created from the time it is terminated.

38
Scheduling Criteria / Goals
5. Wait Time:
• The average period of time a process spends waiting.

39
Scheduling Criteria / Goals
6. Response Time:
• On an interactive systems, the average time it takes
the system to start responding to the user inputs.

40
Scheduling Criteria / Goals
7. Predictability:
• Lack of variability in other measures of performance.
• Users prefer consistency
• For example: response time in an interactive systems is
generally a second but occasionally they take 10s to
respond….such systems are not preferred by users

41
Scheduling Criteria / Goals
8. Fairness:
• The degree to which all the processes are given equal
opportunity to execute.
• Systems which do not allow a process to suffer from
Starvation, i.e, a process is stuck in a scheduling queue
indefinitely.

42
Scheduling Criteria / Goals
9. Priorities:
• Give preferential treatment to processes with higher
priority.

43
Optimization Criteria
• Max CPU utilization
• Max throughput
• Min turnaround time
• Min waiting time
• Min response time

44
Scheduling Algorithm Goals – To identify the process whose selection will result
in the “BEST” possible system performance

45

You might also like