SlideShare a Scribd company logo
1 of 87
Operating System
Process Management & CPU
Scheduling
Presented by,
Priyanka D. Deosarkar
Contents
Process Concept
Process State Models
Process Control Block
CPU scheduling
Process and Thread
Common OS System Components
Process Management and CPU scheduling
Main Memory Management
File Management
I/O System Management
Secondary Storage Management
Networking
Protection System
Command-Interpreter System
O/S as a resource manager
I/O Controller
I/O Controller
I/O Controller
Processor
Processor
Memory
O/S
Programs
&
Data
Storage
O/S
Programs
&
Data
Printer
Key Board
Digital Camera
What is a Process?
A process is a program in execution. Process is not as same as
program code but a lot more than it. A process is an 'active'
entity as opposed to program which is considered to be a
'passive' entity. Attributes held by process include hardware
state, memory, CPU etc.
Process memory is divided into four sections for efficient
working :
The text section is made up of the compiled program code,
read in from non-volatile storage when the program is
launched.
The data section is made up the global and static variables,
allocated and initialized prior to executing the main.
The heap is used for the dynamic memory allocation, and
is managed via calls to new, delete, malloc, free, etc.
The stack is used for local variables. Space on the stack is
reserved for local variables when they are declared.
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
Creation of a process
When a new process is added , O/S builds various
data structures to manage the newly added
process. It also allocates 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
ā—¦ Spawned by existing process: The action of
creating a new process (Child Process) at the
explicit request of another process (Parent
Process) is called as process spawning.
E.g. A print server or file server may generate a
new process for each request that it handles
Process Termination
Normal Completion
Time limit Exceeded: interactive process
Memory unavailable: limit on max no of processes
Bound 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
Privileged Instruction: changing mode from 0 to 1
Data Misuse
Operator / O/S intervention: deadlock occurs
Parent Termination
Parent Request
Two state process model
Not Running Running
Enter Exit
Enter
queue
Dispatch
Processor
Exit
Pause
Disadvantages of two state
model
Dispatcher portion of O/S does not
know whether process is blocked due
to I/O operation to get completed or
process is in ready state to execute
PROCESS STATE
Processes can be any of the following
states :
New - The process is being created.
Ready - The process is waiting to be
assigned to a processor.
Running - Instructions are being
executed.
Waiting - The process is waiting for
some event to occur(such as an I/O
completion or reception of a signal).
Terminated - The process has finished
execution.
Process State diagram[1]
Possible Transitions
Null ļƒ New : New process is created to
execute a program
New ļƒ  Ready
Readyļƒ  Running
Running ļƒ  Exit
Running ļƒ  Ready
Running ļƒ  Blocked/Waiting
Blocked ļƒ  Ready
Ready ļƒ  Exit ( not shown in diagram)
Blocked ļƒ  Exit
Process State Transition
Diagram[2]
Single blocked Queue
Processor
Ready Q
Admit
Dispatch
Release
Time Out
Blocked Queue
Event wait
Event
Occurs
Multiple blocked queue blocked Queue
Processor
Ready Q
Admit
Dispatch
Release
Event 2
Occurs
Time Out
Blocked 1 Queue
Event 1 wait
Blocked 2 Queue
Event 2 wait
Blocked n Queue
Event n wait
Reasons for process
suspension
Swapping: o/s needs to release sufficient
main memory to bring in a process that is
ready to execute
Other O/S reason: o/s may suspend a
background process or it suspects that
process can cause a problem
Timing: Process needs periodic execution
Parent Process Request: To co-ordinate/
examine the child processes, parents
suspends child process
Interactive user input: User wants to suspend
the process for debugging purpose
Process State Transition with suspend
states[3]
new
Admit
Ready
/Suspend
Ready
Admit
Activate
Suspend
Running
Dispatch
Timeout
Exit
Release
Blocked/
Suspend
Blocked
Event
Wait
Event
Occurs
Activate
Suspend
Suspend
New Transitions
Blocked ļƒ  Blocked/Suspend
Blocked/Suspendļƒ  Ready/ Suspend
Ready/Suspendļƒ  Ready
Ready ļƒ  Ready/Suspend
Newļƒ  Ready/Suspend and Newļƒ 
Ready
Blocked/Suspendļƒ  Blocked
Runningļƒ  Ready/Suspend
Any State ļƒ  Exit
Characteristics of suspended
process
The process is not immediately
available for execution
The process may or may not wait for
event
If waiting and if event takes place, the
process cannot be executed
immediately.
Either process itself or parent or o/s
makes state process as suspended,
and it cannot be removed from this
state until agent explicitly orders the
General Structure of o/s Control Tables
Memory
Devices
Files
M
F
Process n
Process
1
Process
n
Process
Image
Pri
emory Tables
I/O Tables
ile Tables
mary Process
Table
Process 1
Process 2
Process 3
Processes
Process
Image
Memory Tables
Used to keep track of both main and
secondary memory.
Processes can be in main or secondary
memory.
Memory tables include information such as
ā—¦ Allocation of main memory to processes
ā—¦ Allocation of Secondary memory to processes
ā—¦ Protection attributes of blocks of main and virtual
memory
ā—¦ Any information needed to manage virtual
memory
I/O and File Tables
I/O tables are used by O/S to manage the
i/o devices and channels
In case of i/o operation in progress, O/S
needs to know status of i/o operation and
location in main memory being used as
source or destination of i/o transfer
File tables provide information about the
existence of files,
secondary memory,
their
current
location on
status, and
other attributes
Process Image Consists of
User Data: Modifiable part of user space
User Program: The program to be
executed
Stack: At least one stack associated
with every process , to store parameters
and calling addresses for procedure and
system calls.
Process Control block: Data needed by
O/S to control the process
Process Control Block : Stores Information
of 3 Categories
Process Identification
ā—¦ Id of the process
ā—¦ Id of Parent Process
ā—¦ User Id
Processor State Information
ā—¦ User Visible Registers: Register referenced by
machine instruction
ā—¦ Control and Status Registers: Program Counter,
Condition Codes (zero, sign, parity etc flags),
status information ( interrupt enabled/disabled flag,
execution mode)
ā—¦ Stack Pointers
Processor Control Information
Process Control Information
Scheduling and State information
ā—¦ Process State: Ready/running/waiting etc
ā—¦ Priority
ā—¦ Scheduling related information: amount of time process has been
waiting, amount of time process executed last time
ā—¦ Event: Identity of event the process is waiting for
Data Structuring: queues, pointers to various tables
IPC: Flags, signals, messages associated with
communication between two independent processes
Process Privileges: memory regions, CPU instructions,
use of system utilities and services
Memory Management: Pointers to page tables that
describe virtual memory assigned to the process
Resource Ownership and Utilization: opened files,
utilization of processor etc
Typical Process Control Block (PCB)
Process List Structure
Running
Ready
Blocked
Process
Control Block
Process Creation
Assign a unique process id to the new process
Allocate space for the process : Includes all
parts of process image
Initialize Process Control Block: Process id,
parent id, Processor state information, program
counter (set to entry point), system stack pointer,
process state, priority etc
Set appropriate linkages: scheduling queue as
linked list
Create or expand data structures: accounting
file
Process Creation
Parent process create children processes,
which, in turn create other processes, forming a
tree of processes.
Resource sharing
ā—¦ Parent and children share all resources.
ā—¦ Children share subset of parentā€™s resources.
ā—¦ Parent and child share no resources.
Execution
ā—¦ Parent and children execute concurrently.
ā—¦ Parent waits until children terminate.
Process Creation (Cont.)
Address space
ā—¦ Child duplicate of parent.
ā—¦ Child has a program loaded into it.
UNIX examples
ā—¦ fork system call creates new process
ā—¦ exec system call used after a fork to
replace the processā€™ memory space with a
new program.
Processes, Address Space
Process: Program in execution
We think of process as an
Abstraction of memory ā€“ address space
Abstraction of one or more processors as threads
Address space means the set of addresses
the program can generate and storage
associated with these addresses.
Processes do not have access to other
processesā€™ address space. This is achieved
through address translation hardware and
support from OS
Assume single thread per process
PROCESS CONTROL BLOCK
There is a Process Control Block 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 - Eg. 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,
PROCESS CONTROL BLOCK
Process Scheduling
The act of determining which process in the ready
state should be moved to the running state is
known as Process Scheduling.
The prime aim of the process scheduling system is
to keep the CPU busy all the time and to deliver
minimum response time for all programs. For
achieving this, the scheduler must apply
appropriate rules for swapping processes IN and
OUT of CPU.
Schedulers fell into one of the two general
categories :
Non pre-emptive scheduling : When the currently
executing process gives up the CPU voluntarily.
Pre-emptive scheduling : When the operating
system decides to favour another process, pre-
empting the currently executing process.
Scheduling Queues
All processes when enters into the system are stored in
the job queue.
Processes in the Ready state are placed in the ready
queue.
Processes waiting for a device to become available are
placed in device queues. There are unique device queues
for each I/O device available.
A new process is initially put in the ready queue. It waits in
the ready queue until it is selected for execution(or
dispatched). Once the process is assigned to the CPU and
is executing, once of several events could occur.
The process could issue an I/O request, and then be
placed in an I/O queue.
The process could create a new subprocess and wait for
its termination.
The process could be removed forcibly from the CPU, as a
result of an interrupt, and be put back in the ready queue.
In the first two cases, the process eventually switches from the
waiting state to the ready state, and is then put back in the
ready queue. A process continues this cycle until it terminates,
at which time it is removed from all queues and has its PCB
and resources deallocated.[4]
Types of Schedulers
There are three types of schedulers available :
Long Term Scheduler :Long term scheduler runs less
frequently. 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. 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.
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.
Medium Term Scheduler :This scheduler removes the
processes from memory (and from active contention for
Types of Schedulers
At some later time, the process can be
reintroduced into memory and its
execution van be continued where it left
off. This scheme is called swapping.
The process is swapped out, and is later
swapped in, by the medium term
scheduler.
Swapping may be necessary to improve
the process mix, or because a change in
memory requirements has
overcommitted available memory,
requiring memory to be freed up. This
complete process is descripted in the
below diagram:
Addition of medium-term scheduling to the queueing diagram.[5]
Context Switch
Switching the CPU to another process requires saving the
state of the old process and loadingthe saved state for the
new process. This task is known as a context switch.
The context of a process is represented in the Process
Control Block(PCB) of a process; it includes the value of the
CPU registers, the process state and memory-management
information. When a context switch occurs, the Kernel saves
the context of the old process in its PCB and loads the saved
context of the new process scheduled to run.
Context switch time is pure overhead, because the system
does no useful work while switching. Its speed varies from
machine to machine, depending on the memory speed, the
number of registers that must be copied, and the existence of
special instructions(such as a single instruction to load or
store all registers). Typical speeds range from 1 to 1000
microseconds.
Context Switching has become such a
performance bottleneck that programmers are usingnew
structures(threads) to avoid it whenever possible.
Operations on Process
Process Creation
Through appropriate system calls, such as fork or
spawn, processes may create other processes. The
process which creates other process, is termed
the parent of the other process, while the created sub-
process is termed its child.
Each process is given an integer identifier, termed as
process identifier, or PID. The parent PID (PPID) is also
stored for each process.
On a typical UNIX systems the process scheduler is
termed as sched, and is given PID 0. The first thing
done by it at system start-up time is to launch init, which
gives that process PID 1. Further Init launches all the
system daemons and user logins, and becomes the
ultimate parent of all other processes.
A child process may receive some amount of shared
resources with its parent depending on system
implementation. To prevent runaway children from consuming
all of a certain system resource, child processes may or may
not be limited to a subset of the resources originally allocated
to the parent.
There are two options for the parent process after creating
the child :
Wait for the child process to terminate before proceeding.
Parent process makes a wait() system call, for either a
specific child process or for any particular child process,
which causes the parent process to block until
the wait() returns. UNIX shells normally wait for their children
to complete before issuing a new prompt.
Run concurrently with the child, continuing to process without
waiting. When a UNIX shell runs a process as a background
task, this is the operation seen. It is also possible for the
parent to run for a while, and then wait for the child later,
which might occur in a sort of a parallel processing operation.
here are also two possibilities in terms of the address space of the
new process:
The child process is a duplicate of the parent process.
The child process has a program loaded into it.
To illustrate these different implementations, let us consider
the UNIX operating system. In UNIX, each process is identified by
its process identifier, which is a unique integer. A new process is
created by the fork system call. The new process consists of a copy
of the address space of the original process. This mechanism allows
the parent process to communicate easily with its child process.
Both processes (the parent and the child) continue execution at the
instruction after the fork system call, with one difference: The return
code for the fork system call is zero for the new(child) process,
whereas the(non zero) process identifier of the child is returned
to the parent.
Typically, the execlp system call is used after the fork system call
by one of the two processes to replace the process memory space
with a new program. The execlp system call loads a binary file into
memory - destroying the memory image of the program containing
the execlp system call ā€“ and starts its execution. In this manner the
two processes are able to communicate, and then to go their
separate ways.
Process Termination
By making the exit(system call), typically returning an int,
processes may request their own termination. This int is
passed along to the parent if it is doing a wait(), and is
typically zero on successful completion and some non-zero
code in the event of any problem.
Processes may also be terminated by the system for a variety
of reasons, including :
The inability of the system to deliver the necessary system
resources.
In response to a KILL command or other unhandledprocess
interrupts.
A parent may kill its children if the task assigned to them isno
longer needed i.e. if the need of having a child terminates.
If the parent exits, the system may or may not allow the child
to continue without a parent (In UNIX systems, orphaned
processes are generally inherited by init, which then proceeds
to kill them.)
When a process ends, all of its system
resources are freed up, open files
flushed and closed, etc. The process
termination status and execution times
are returned to the parent if the parent is
waiting for the child to terminate, or
eventually returned to init if the process
already became an orphan.
The processes which are trying to
terminate but cannot do so because their
parent is not waiting for them are
termed zombies. These are eventually
inherited by init as orphans and killed off.
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. The aim of CPU
scheduling is to make the system efficient, fast
and fair.
Whenever the CPU becomes idle, the operating
system must select one of the processes in the
ready queue to be executed. The selection
process is carried out by the short-term
scheduler (or CPU scheduler). The scheduler
selects from among the processes in memory
that are ready to execute, and allocates the CPU
to one of them.
Dispatcher
Another component involved in the CPU scheduling
function is the dispatcher. The dispatcher is the
module that gives control of the CPU to the process
selected by the short-term scheduler. This function
involves:
Switching context
Switching to user mode
Jumping to the proper location in the user program to
restart that program
The dispatcher should be as fast as possible, given that
it is invoked during every process switch. The time it
takes for the dispatcher to stop one process and start
another running is known as the dispatch latency.
Dispatch Latency can be explained using the below
figure:
Types of CPU Scheduling
CPU scheduling decisions may take place under the following
four circumstances:
When a process switches from the running state to
the waiting state(for I/O request or invocation of wait forthe
termination of one of the child processes).
When a process switches from the running state to
the ready state (for example, when an interrupt occurs).
When a process switches from the waiting state to
the ready state(for example, completion of I/O).
When a process terminates.
In circumstances 1 and 4, there is no choice in terms of
scheduling. A new process(if one exists in the ready queue)
must be selected for execution. There is a choice, howeverin
circumstances 2 and 3.
When Scheduling takes place only under circumstances 1
and 4, we say the scheduling scheme is non-preemptive;
otherwise the scheduling scheme is preemptive.
Non-Preemptive Scheduling
Under non-preemptive scheduling, once the
CPU has been allocated to a process, the
process keeps the CPU until it releases the
CPU either by terminating or by switching to
the waiting state.
This scheduling method is used by the
Microsoft Windows 3.1 and by the Apple
Macintosh operating systems.
It is the only method that can be used on
certain hardware platforms, because It does
not require the special hardware(for example:
a timer) needed for preemptive scheduling.
Preemptive 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.
Scheduling Criteria
User Oriented Other
User Oriented
Performance related
System Oriented
Other
System Oriented
Performance related
Predictability
Turnaround
Time
Response
Time
Deadlines
Fairness
Enforcing
Priorities
Balancing
Resources
Throughput Processor
Utilization
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
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
Scheduling Algorithms
Non-preemptive: Once a process is in the
ready state, it continues to execute until
ā—¦ It terminates itself
ā—¦ It blocks itself to wait for I/O
ā—¦ It requests OS service
Preemptive: The currently running process may
be interrupted and moved to ready state by OS.
Preemption takes place because
ā—¦ Time period is expired
ā—¦ Higher priority process arrives
ā—¦ Blocked process becomes unblocked and has higher
priority
Scheduling Algorithms
Four major scheduling algorithms here
which are following :
First Come First Serve(FCFS)
Scheduling
Shortest-Job-First(SJF) Scheduling
Priority Scheduling
Round Robin(RR) Scheduling
Multilevel Queue Scheduling
Multilevel Feedback Queue
Scheduling
First Come First Serve(FCFS)
Scheduling
Jobs are executed on first come, first
serve basis.
Easy to understand and implement.
Poor in performance as average wait
time is high.
Shortest-Job-First(SJF)
Scheduling
Best approach to minimize waiting
time.
Actual time taken by the process is
already known to processor.
Impossible to implement.
FCFS (non-preemptive)
P1
P2
P3
P4
0.0
2.0
4.0
5.0
ProcessArrival Time Burst Time
7
4
1
4
Example of FCFS
FCFS (non-preemptive)
Average waiting time = (0 + 5 + 7 + 7)/4 = 4.75
Average Turnaround Time = (7+9+8+11)/4=8.75
P1 P2 P3 P4
0 7 11 12 16
Shortest Job First (SPN: Shortest Process Next)
This is a non-preemptive policy in which the process
with the shortest expected processing time is selected
next. Thus a short process will jump to the head of the
queue. This type of policy needs to know or at least
estimate the required processing time of each process.
Selection Function: minimum total service time
required by the process, including time spent in
execution so far.
Decision Mode : Non_preemptive
Throughput: High
Response Time: Provides good response time for short
processes.
Overhead: Can be high
Effect on Processes: Penalizes long processes.
Starvation: Possible
Example of Non-Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
SJF (non-preemptive)
P1 P3 P2 P4
0 3 7 8 12 16
Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Average turnaround time=(7+10+4+11)/4=8
Shortest Job First Preemptive or Shortest Remaining
Time
It is a preemptive version of SJF. In this policy, scheduler
always chooses the process that has the shortest
expected remaining processing time. When a new
process arrives in the ready queue, it may in fact have a
shorter remaining time than the currently running
process. Accordingly, the scheduler may preempt
whenever a new process becomes ready. Scheduler
must have an estimate of processing time to perform the
selection function.
Selection Function: minimum total service time
required by the process, minus time spent in execution
so far.
Decision Mode : Preemptive ( At arrival time)
Throughput: High
Response Time: Provides good response time
Overhead: Can be high
Effect on Processes: Penalizes long processes.
Starvation: Possible
Example of Preemptive SJF
Process Arrival Time BurstTime
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
ā€¢ Average waiting time = (9 + 1 + 0 +2)/4 = 3
ā€¢ Average turnaround time= (16+5+1+6)/4=7
0
P4
2 4 5 7
ā€¢ SJF (preemptive)
P1 P2 P3 P2 P1
11 16
Round robin
This algorithm is especially implemented for time sharing systems . It
is similar to FCFS but preemption is added to switch between
processes. A small unit of time called as Time Quantum is defined (
10 to 100 milliseconds ) . The ready queue is treated as a circular
queue. 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 tail of the queue . The average waiting
time is often quite long. It is preemptive . The algorithmā€™s
performance heavily depends upon the time quantum, and so thus
the turnaround time . It degenerates to FCFS if time quantum is
large.
Selection Function: Constant
Decision Mode : Preemptive ( At time quantum)
Throughput: May be low if time quantum is too small
Response Time: Provides good response time for short
processes.
Overhead: minimum
Effect on Processes: Fair treatment
Starvation: No
Example of Round Robin
Process Arrival Time BurstTime
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
ā€¢ Round Robin (By Default preemptive: Time Quantum 2)
P1 P2 P1 P3 P2 P4 P1 P4 P1
0 2 4 6 7 9 11 13 15 16
ā€¢ Average waiting time = (9 + 3 + 2 +6)/4 =5
ā€¢ Average turnaround time =(16+7+3+10)/4=9
Feedback Scheduling
Processor
Ready Queue (0)
Ready queue n
Ready Queue 2
Ready 1
Release
Admit
Processor
Processor
Processor
Release
Release
Release
In Preemptive Shortest Job First
Scheduling, jobs are put into ready
queue as they arrive, but as a process
with short burst time arrives, the
existing process is preempted.
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 FCFS
manner.
Priority can be decided based on memory
requirements, time requirements or any other
resource requirement.
Round Robin(RR) Scheduling
A fixed time is allotted to each process,
called quantum, for execution.
Once a process is executed for given time period
that process is preemptied and other process
executes for given time period.
Context switching is used to save states of
preemptied processes.
Multilevel Queue Scheduling
Another class of scheduling algorithms has been created for
situations in which processes are easily classified into different
groups.
For example: A common division is made between foreground(or
interactive) processes and background (or batch) processes. These
two types of processes have different response-time requirements,
and so might have different scheduling needs. In addition,
foreground processes may have priority over background processes.
A multi-level queue scheduling algorithm partitions the ready queue
into several separate queues. The processes are permanently
assigned to one queue, generally based on some property of the
process, such as memory size, process priority, or process type.
Each queue has its own scheduling algorithm.
For example: separate queues might be used for foreground and
background processes. The foreground queue might be scheduled
by Round Robin algorithm, while the background queue is
scheduled by an FCFS algorithm.
In addition, there must be scheduling among the queues, which is
commonly implemented as fixed-priority preemptive scheduling. For
example: The foreground queue may have absolute priority over the
background queue.
Let us consider an example of a multilevel queue-
scheduling algorithm with five queues:
System Processes
Interactive Processes
Interactive Editing Processes
Batch Processes
Student Processes
Each queue has absolute priority over lower-priority
queues. No process in the batch queue, for example,
could run unless the queues for system processes,
interactive processes, and interactive editing processes
were all empty. If an interactive editing process entered
the ready queue while a batch process was running, the
batch process will be preempted.
Multilevel Feedback Queue
Scheduling
In a multilevel queue-scheduling algorithm,
processes are permanently assigned to a queue
on entry to the system. Processes do not move
between queues. This setup has the advantage
of low scheduling overhead, but the
disadvantage of being inflexible.
Multilevel feedback queue scheduling, however,
allows a process to move between queues. The
idea is to separate processes with different CPU-
burst characteristics. If a process uses too much
CPU time, it will be moved to a lower-priority
queue. Similarly, a process that waits too long in
a lower-priority queue may be moved to a higher-
priority queue. This form of aging prevents
starvation.
An example of a multilevel
feedback queue can be seen in the
below figure.
In general, a multilevel feedback queue scheduler is
defined by the following parameters:
The number of queues.
The scheduling algorithm for each queue.
The method used to determine when to upgrade a
process to a higher-priority queue.
The method used to determine when to demote a
process to a lower-priority queue.
The method used to determine which queue a process
will enter when that process needs service.
The definition of a multilevel feedback queue scheduler
makes it the most general CPU-scheduling algorithm. It
can be configured to match a specific system under
design. Unfortunately, it also requires some means of
selecting values for all the parameters to define the best
scheduler. Although a multilevel feedback queue is
the most general scheme, it is also the most complex.

More Related Content

Similar to Operating System Process Scheduling.pptx

Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdfHikaTariku
Ā 
OS-Process.pdf
OS-Process.pdfOS-Process.pdf
OS-Process.pdfRakibul Rakib
Ā 
Lecture 2- Processes.pdf
Lecture 2- Processes.pdfLecture 2- Processes.pdf
Lecture 2- Processes.pdfAmanuelmergia
Ā 
Ch2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptCh2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptMohammad Almuiet
Ā 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2Kathirvel Ayyaswamy
Ā 
Operating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptxOperating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptxAmanuelmergia
Ā 
Operating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptxOperating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptxAmanuelmergia
Ā 
Process management
Process managementProcess management
Process managementBirju Tank
Ā 
Os4 2
Os4 2Os4 2
Os4 2issbp
Ā 
Process Basics.ppt
Process Basics.pptProcess Basics.ppt
Process Basics.pptCharuJain396881
Ā 
Operating system
Operating systemOperating system
Operating systemMark Muhama
Ā 
Lecture_Slide_4.pptx
Lecture_Slide_4.pptxLecture_Slide_4.pptx
Lecture_Slide_4.pptxDiptoRoy21
Ā 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of ProcessShipra Swati
Ā 
OperatingSystem02..(B.SC Part 2)
OperatingSystem02..(B.SC Part 2)OperatingSystem02..(B.SC Part 2)
OperatingSystem02..(B.SC Part 2)Muhammad Osama
Ā 

Similar to Operating System Process Scheduling.pptx (20)

CH03.pdf
CH03.pdfCH03.pdf
CH03.pdf
Ā 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdf
Ā 
OS-Process.pdf
OS-Process.pdfOS-Process.pdf
OS-Process.pdf
Ā 
Lecture 2- Processes.pdf
Lecture 2- Processes.pdfLecture 2- Processes.pdf
Lecture 2- Processes.pdf
Ā 
Ch2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptCh2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.ppt
Ā 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
Ā 
Operating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptxOperating Systems chap 2_updated2 (1).pptx
Operating Systems chap 2_updated2 (1).pptx
Ā 
Operating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptxOperating Systems chap 2_updated2.pptx
Operating Systems chap 2_updated2.pptx
Ā 
unit-2.pdf
unit-2.pdfunit-2.pdf
unit-2.pdf
Ā 
Process management
Process managementProcess management
Process management
Ā 
Cs8493 unit 2
Cs8493 unit 2Cs8493 unit 2
Cs8493 unit 2
Ā 
Os4 2
Os4 2Os4 2
Os4 2
Ā 
Processes
ProcessesProcesses
Processes
Ā 
Process Basics.ppt
Process Basics.pptProcess Basics.ppt
Process Basics.ppt
Ā 
Os
OsOs
Os
Ā 
Os
OsOs
Os
Ā 
Operating system
Operating systemOperating system
Operating system
Ā 
Lecture_Slide_4.pptx
Lecture_Slide_4.pptxLecture_Slide_4.pptx
Lecture_Slide_4.pptx
Ā 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of Process
Ā 
OperatingSystem02..(B.SC Part 2)
OperatingSystem02..(B.SC Part 2)OperatingSystem02..(B.SC Part 2)
OperatingSystem02..(B.SC Part 2)
Ā 

Recently uploaded

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
Ā 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
Ā 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
Ā 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
Ā 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
Ā 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
Ā 
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøcall girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø9953056974 Low Rate Call Girls In Saket, Delhi NCR
Ā 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
Ā 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
Ā 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
Ā 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
Ā 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
Ā 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
Ā 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
Ā 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
Ā 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
Ā 

Recently uploaded (20)

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
Ā 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
Ā 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
Ā 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
Ā 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
Ā 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Ā 
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøcall girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
Ā 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
Ā 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Ā 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
Ā 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
Ā 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
Ā 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
Ā 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
Ā 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
Ā 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
Ā 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
Ā 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
Ā 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
Ā 

Operating System Process Scheduling.pptx

  • 1. Operating System Process Management & CPU Scheduling Presented by, Priyanka D. Deosarkar
  • 2. Contents Process Concept Process State Models Process Control Block CPU scheduling Process and Thread
  • 3. Common OS System Components Process Management and CPU scheduling Main Memory Management File Management I/O System Management Secondary Storage Management Networking Protection System Command-Interpreter System
  • 4. O/S as a resource manager I/O Controller I/O Controller I/O Controller Processor Processor Memory O/S Programs & Data Storage O/S Programs & Data Printer Key Board Digital Camera
  • 5. What is a Process? A process is a program in execution. Process is not as same as program code but a lot more than it. A process is an 'active' entity as opposed to program which is considered to be a 'passive' entity. Attributes held by process include hardware state, memory, CPU etc. Process memory is divided into four sections for efficient working : The text section is made up of the compiled program code, read in from non-volatile storage when the program is launched. The data section is made up the global and static variables, allocated and initialized prior to executing the main. The heap is used for the dynamic memory allocation, and is managed via calls to new, delete, malloc, free, etc. The stack is used for local variables. Space on the stack is reserved for local variables when they are declared.
  • 6. 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
  • 7. Creation of a process When a new process is added , O/S builds various data structures to manage the newly added process. It also allocates 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 ā—¦ Spawned by existing process: The action of creating a new process (Child Process) at the explicit request of another process (Parent Process) is called as process spawning. E.g. A print server or file server may generate a new process for each request that it handles
  • 8. Process Termination Normal Completion Time limit Exceeded: interactive process Memory unavailable: limit on max no of processes Bound 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 Privileged Instruction: changing mode from 0 to 1 Data Misuse Operator / O/S intervention: deadlock occurs Parent Termination Parent Request
  • 9. Two state process model Not Running Running Enter Exit Enter queue Dispatch Processor Exit Pause
  • 10. Disadvantages of two state model Dispatcher portion of O/S does not know whether process is blocked due to I/O operation to get completed or process is in ready state to execute
  • 11. PROCESS STATE Processes can be any of the following states : New - The process is being created. Ready - The process is waiting to be assigned to a processor. Running - Instructions are being executed. Waiting - The process is waiting for some event to occur(such as an I/O completion or reception of a signal). Terminated - The process has finished execution.
  • 13. Possible Transitions Null ļƒ New : New process is created to execute a program New ļƒ  Ready Readyļƒ  Running Running ļƒ  Exit Running ļƒ  Ready Running ļƒ  Blocked/Waiting Blocked ļƒ  Ready Ready ļƒ  Exit ( not shown in diagram) Blocked ļƒ  Exit
  • 15. Single blocked Queue Processor Ready Q Admit Dispatch Release Time Out Blocked Queue Event wait Event Occurs
  • 16. Multiple blocked queue blocked Queue Processor Ready Q Admit Dispatch Release Event 2 Occurs Time Out Blocked 1 Queue Event 1 wait Blocked 2 Queue Event 2 wait Blocked n Queue Event n wait
  • 17. Reasons for process suspension Swapping: o/s needs to release sufficient main memory to bring in a process that is ready to execute Other O/S reason: o/s may suspend a background process or it suspects that process can cause a problem Timing: Process needs periodic execution Parent Process Request: To co-ordinate/ examine the child processes, parents suspends child process Interactive user input: User wants to suspend the process for debugging purpose
  • 18. Process State Transition with suspend states[3] new Admit Ready /Suspend Ready Admit Activate Suspend Running Dispatch Timeout Exit Release Blocked/ Suspend Blocked Event Wait Event Occurs Activate Suspend Suspend
  • 19. New Transitions Blocked ļƒ  Blocked/Suspend Blocked/Suspendļƒ  Ready/ Suspend Ready/Suspendļƒ  Ready Ready ļƒ  Ready/Suspend Newļƒ  Ready/Suspend and Newļƒ  Ready Blocked/Suspendļƒ  Blocked Runningļƒ  Ready/Suspend Any State ļƒ  Exit
  • 20. Characteristics of suspended process The process is not immediately available for execution The process may or may not wait for event If waiting and if event takes place, the process cannot be executed immediately. Either process itself or parent or o/s makes state process as suspended, and it cannot be removed from this state until agent explicitly orders the
  • 21. General Structure of o/s Control Tables Memory Devices Files M F Process n Process 1 Process n Process Image Pri emory Tables I/O Tables ile Tables mary Process Table Process 1 Process 2 Process 3 Processes Process Image
  • 22. Memory Tables Used to keep track of both main and secondary memory. Processes can be in main or secondary memory. Memory tables include information such as ā—¦ Allocation of main memory to processes ā—¦ Allocation of Secondary memory to processes ā—¦ Protection attributes of blocks of main and virtual memory ā—¦ Any information needed to manage virtual memory
  • 23. I/O and File Tables I/O tables are used by O/S to manage the i/o devices and channels In case of i/o operation in progress, O/S needs to know status of i/o operation and location in main memory being used as source or destination of i/o transfer File tables provide information about the existence of files, secondary memory, their current location on status, and other attributes
  • 24. Process Image Consists of User Data: Modifiable part of user space User Program: The program to be executed Stack: At least one stack associated with every process , to store parameters and calling addresses for procedure and system calls. Process Control block: Data needed by O/S to control the process
  • 25. Process Control Block : Stores Information of 3 Categories Process Identification ā—¦ Id of the process ā—¦ Id of Parent Process ā—¦ User Id Processor State Information ā—¦ User Visible Registers: Register referenced by machine instruction ā—¦ Control and Status Registers: Program Counter, Condition Codes (zero, sign, parity etc flags), status information ( interrupt enabled/disabled flag, execution mode) ā—¦ Stack Pointers Processor Control Information
  • 26. Process Control Information Scheduling and State information ā—¦ Process State: Ready/running/waiting etc ā—¦ Priority ā—¦ Scheduling related information: amount of time process has been waiting, amount of time process executed last time ā—¦ Event: Identity of event the process is waiting for Data Structuring: queues, pointers to various tables IPC: Flags, signals, messages associated with communication between two independent processes Process Privileges: memory regions, CPU instructions, use of system utilities and services Memory Management: Pointers to page tables that describe virtual memory assigned to the process Resource Ownership and Utilization: opened files, utilization of processor etc
  • 27. Typical Process Control Block (PCB)
  • 29. Process Creation Assign a unique process id to the new process Allocate space for the process : Includes all parts of process image Initialize Process Control Block: Process id, parent id, Processor state information, program counter (set to entry point), system stack pointer, process state, priority etc Set appropriate linkages: scheduling queue as linked list Create or expand data structures: accounting file
  • 30. Process Creation Parent process create children processes, which, in turn create other processes, forming a tree of processes. Resource sharing ā—¦ Parent and children share all resources. ā—¦ Children share subset of parentā€™s resources. ā—¦ Parent and child share no resources. Execution ā—¦ Parent and children execute concurrently. ā—¦ Parent waits until children terminate.
  • 31. Process Creation (Cont.) Address space ā—¦ Child duplicate of parent. ā—¦ Child has a program loaded into it. UNIX examples ā—¦ fork system call creates new process ā—¦ exec system call used after a fork to replace the processā€™ memory space with a new program.
  • 32. Processes, Address Space Process: Program in execution We think of process as an Abstraction of memory ā€“ address space Abstraction of one or more processors as threads Address space means the set of addresses the program can generate and storage associated with these addresses. Processes do not have access to other processesā€™ address space. This is achieved through address translation hardware and support from OS Assume single thread per process
  • 33. PROCESS CONTROL BLOCK There is a Process Control Block 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 - Eg. 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,
  • 35. Process Scheduling The act of determining which process in the ready state should be moved to the running state is known as Process Scheduling. The prime aim of the process scheduling system is to keep the CPU busy all the time and to deliver minimum response time for all programs. For achieving this, the scheduler must apply appropriate rules for swapping processes IN and OUT of CPU. Schedulers fell into one of the two general categories : Non pre-emptive scheduling : When the currently executing process gives up the CPU voluntarily. Pre-emptive scheduling : When the operating system decides to favour another process, pre- empting the currently executing process.
  • 36. Scheduling Queues All processes when enters into the system are stored in the job queue. Processes in the Ready state are placed in the ready queue. Processes waiting for a device to become available are placed in device queues. There are unique device queues for each I/O device available. A new process is initially put in the ready queue. It waits in the ready queue until it is selected for execution(or dispatched). Once the process is assigned to the CPU and is executing, once of several events could occur. The process could issue an I/O request, and then be placed in an I/O queue. The process could create a new subprocess and wait for its termination. The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue.
  • 37. In the first two cases, the process eventually switches from the waiting state to the ready state, and is then put back in the ready queue. A process continues this cycle until it terminates, at which time it is removed from all queues and has its PCB and resources deallocated.[4]
  • 38. Types of Schedulers There are three types of schedulers available : Long Term Scheduler :Long term scheduler runs less frequently. 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. 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. 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. Medium Term Scheduler :This scheduler removes the processes from memory (and from active contention for
  • 40.
  • 41. At some later time, the process can be reintroduced into memory and its execution van be continued where it left off. This scheme is called swapping. The process is swapped out, and is later swapped in, by the medium term scheduler. Swapping may be necessary to improve the process mix, or because a change in memory requirements has overcommitted available memory, requiring memory to be freed up. This complete process is descripted in the below diagram:
  • 42. Addition of medium-term scheduling to the queueing diagram.[5]
  • 43. Context Switch Switching the CPU to another process requires saving the state of the old process and loadingthe saved state for the new process. This task is known as a context switch. The context of a process is represented in the Process Control Block(PCB) of a process; it includes the value of the CPU registers, the process state and memory-management information. When a context switch occurs, the Kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run. Context switch time is pure overhead, because the system does no useful work while switching. Its speed varies from machine to machine, depending on the memory speed, the number of registers that must be copied, and the existence of special instructions(such as a single instruction to load or store all registers). Typical speeds range from 1 to 1000 microseconds. Context Switching has become such a performance bottleneck that programmers are usingnew structures(threads) to avoid it whenever possible.
  • 44.
  • 45. Operations on Process Process Creation Through appropriate system calls, such as fork or spawn, processes may create other processes. The process which creates other process, is termed the parent of the other process, while the created sub- process is termed its child. Each process is given an integer identifier, termed as process identifier, or PID. The parent PID (PPID) is also stored for each process. On a typical UNIX systems the process scheduler is termed as sched, and is given PID 0. The first thing done by it at system start-up time is to launch init, which gives that process PID 1. Further Init launches all the system daemons and user logins, and becomes the ultimate parent of all other processes.
  • 46.
  • 47. A child process may receive some amount of shared resources with its parent depending on system implementation. To prevent runaway children from consuming all of a certain system resource, child processes may or may not be limited to a subset of the resources originally allocated to the parent. There are two options for the parent process after creating the child : Wait for the child process to terminate before proceeding. Parent process makes a wait() system call, for either a specific child process or for any particular child process, which causes the parent process to block until the wait() returns. UNIX shells normally wait for their children to complete before issuing a new prompt. Run concurrently with the child, continuing to process without waiting. When a UNIX shell runs a process as a background task, this is the operation seen. It is also possible for the parent to run for a while, and then wait for the child later, which might occur in a sort of a parallel processing operation.
  • 48. here are also two possibilities in terms of the address space of the new process: The child process is a duplicate of the parent process. The child process has a program loaded into it. To illustrate these different implementations, let us consider the UNIX operating system. In UNIX, each process is identified by its process identifier, which is a unique integer. A new process is created by the fork system call. The new process consists of a copy of the address space of the original process. This mechanism allows the parent process to communicate easily with its child process. Both processes (the parent and the child) continue execution at the instruction after the fork system call, with one difference: The return code for the fork system call is zero for the new(child) process, whereas the(non zero) process identifier of the child is returned to the parent. Typically, the execlp system call is used after the fork system call by one of the two processes to replace the process memory space with a new program. The execlp system call loads a binary file into memory - destroying the memory image of the program containing the execlp system call ā€“ and starts its execution. In this manner the two processes are able to communicate, and then to go their separate ways.
  • 49.
  • 50. Process Termination By making the exit(system call), typically returning an int, processes may request their own termination. This int is passed along to the parent if it is doing a wait(), and is typically zero on successful completion and some non-zero code in the event of any problem. Processes may also be terminated by the system for a variety of reasons, including : The inability of the system to deliver the necessary system resources. In response to a KILL command or other unhandledprocess interrupts. A parent may kill its children if the task assigned to them isno longer needed i.e. if the need of having a child terminates. If the parent exits, the system may or may not allow the child to continue without a parent (In UNIX systems, orphaned processes are generally inherited by init, which then proceeds to kill them.)
  • 51. When a process ends, all of its system resources are freed up, open files flushed and closed, etc. The process termination status and execution times are returned to the parent if the parent is waiting for the child to terminate, or eventually returned to init if the process already became an orphan. The processes which are trying to terminate but cannot do so because their parent is not waiting for them are termed zombies. These are eventually inherited by init as orphans and killed off.
  • 52. 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. The aim of CPU scheduling is to make the system efficient, fast and fair. Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. The selection process is carried out by the short-term scheduler (or CPU scheduler). The scheduler selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them.
  • 53. Dispatcher Another component involved in the CPU scheduling function is the dispatcher. The dispatcher is the module that gives control of the CPU to the process selected by the short-term scheduler. This function involves: Switching context Switching to user mode Jumping to the proper location in the user program to restart that program The dispatcher should be as fast as possible, given that it is invoked during every process switch. The time it takes for the dispatcher to stop one process and start another running is known as the dispatch latency. Dispatch Latency can be explained using the below figure:
  • 54.
  • 55. Types of CPU Scheduling CPU scheduling decisions may take place under the following four circumstances: When a process switches from the running state to the waiting state(for I/O request or invocation of wait forthe termination of one of the child processes). When a process switches from the running state to the ready state (for example, when an interrupt occurs). When a process switches from the waiting state to the ready state(for example, completion of I/O). When a process terminates. In circumstances 1 and 4, there is no choice in terms of scheduling. A new process(if one exists in the ready queue) must be selected for execution. There is a choice, howeverin circumstances 2 and 3. When Scheduling takes place only under circumstances 1 and 4, we say the scheduling scheme is non-preemptive; otherwise the scheduling scheme is preemptive.
  • 56. Non-Preemptive Scheduling Under non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. This scheduling method is used by the Microsoft Windows 3.1 and by the Apple Macintosh operating systems. It is the only method that can be used on certain hardware platforms, because It does not require the special hardware(for example: a timer) needed for preemptive scheduling.
  • 57. Preemptive 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.
  • 58. Scheduling Criteria User Oriented Other User Oriented Performance related System Oriented Other System Oriented Performance related Predictability Turnaround Time Response Time Deadlines Fairness Enforcing Priorities Balancing Resources Throughput Processor Utilization
  • 59. 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
  • 60. 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
  • 61. Scheduling Algorithms Non-preemptive: Once a process is in the ready state, it continues to execute until ā—¦ It terminates itself ā—¦ It blocks itself to wait for I/O ā—¦ It requests OS service Preemptive: The currently running process may be interrupted and moved to ready state by OS. Preemption takes place because ā—¦ Time period is expired ā—¦ Higher priority process arrives ā—¦ Blocked process becomes unblocked and has higher priority
  • 62. Scheduling Algorithms Four major scheduling algorithms here which are following : First Come First Serve(FCFS) Scheduling Shortest-Job-First(SJF) Scheduling Priority Scheduling Round Robin(RR) Scheduling Multilevel Queue Scheduling Multilevel Feedback Queue Scheduling
  • 63. First Come First Serve(FCFS) Scheduling Jobs are executed on first come, first serve basis. Easy to understand and implement. Poor in performance as average wait time is high.
  • 64.
  • 65. Shortest-Job-First(SJF) Scheduling Best approach to minimize waiting time. Actual time taken by the process is already known to processor. Impossible to implement.
  • 67. Example of FCFS FCFS (non-preemptive) Average waiting time = (0 + 5 + 7 + 7)/4 = 4.75 Average Turnaround Time = (7+9+8+11)/4=8.75 P1 P2 P3 P4 0 7 11 12 16
  • 68. Shortest Job First (SPN: Shortest Process Next) This is a non-preemptive policy in which the process with the shortest expected processing time is selected next. Thus a short process will jump to the head of the queue. This type of policy needs to know or at least estimate the required processing time of each process. Selection Function: minimum total service time required by the process, including time spent in execution so far. Decision Mode : Non_preemptive Throughput: High Response Time: Provides good response time for short processes. Overhead: Can be high Effect on Processes: Penalizes long processes. Starvation: Possible
  • 69. Example of Non-Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (non-preemptive) P1 P3 P2 P4 0 3 7 8 12 16 Average waiting time = (0 + 6 + 3 + 7)/4 = 4 Average turnaround time=(7+10+4+11)/4=8
  • 70. Shortest Job First Preemptive or Shortest Remaining Time It is a preemptive version of SJF. In this policy, scheduler always chooses the process that has the shortest expected remaining processing time. When a new process arrives in the ready queue, it may in fact have a shorter remaining time than the currently running process. Accordingly, the scheduler may preempt whenever a new process becomes ready. Scheduler must have an estimate of processing time to perform the selection function. Selection Function: minimum total service time required by the process, minus time spent in execution so far. Decision Mode : Preemptive ( At arrival time) Throughput: High Response Time: Provides good response time Overhead: Can be high Effect on Processes: Penalizes long processes. Starvation: Possible
  • 71. Example of Preemptive SJF Process Arrival Time BurstTime P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 ā€¢ Average waiting time = (9 + 1 + 0 +2)/4 = 3 ā€¢ Average turnaround time= (16+5+1+6)/4=7 0 P4 2 4 5 7 ā€¢ SJF (preemptive) P1 P2 P3 P2 P1 11 16
  • 72. Round robin This algorithm is especially implemented for time sharing systems . It is similar to FCFS but preemption is added to switch between processes. A small unit of time called as Time Quantum is defined ( 10 to 100 milliseconds ) . The ready queue is treated as a circular queue. 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 tail of the queue . The average waiting time is often quite long. It is preemptive . The algorithmā€™s performance heavily depends upon the time quantum, and so thus the turnaround time . It degenerates to FCFS if time quantum is large. Selection Function: Constant Decision Mode : Preemptive ( At time quantum) Throughput: May be low if time quantum is too small Response Time: Provides good response time for short processes. Overhead: minimum Effect on Processes: Fair treatment Starvation: No
  • 73. Example of Round Robin Process Arrival Time BurstTime P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 ā€¢ Round Robin (By Default preemptive: Time Quantum 2) P1 P2 P1 P3 P2 P4 P1 P4 P1 0 2 4 6 7 9 11 13 15 16 ā€¢ Average waiting time = (9 + 3 + 2 +6)/4 =5 ā€¢ Average turnaround time =(16+7+3+10)/4=9
  • 74. Feedback Scheduling Processor Ready Queue (0) Ready queue n Ready Queue 2 Ready 1 Release Admit Processor Processor Processor Release Release Release
  • 75.
  • 76. In Preemptive Shortest Job First Scheduling, jobs are put into ready queue as they arrive, but as a process with short burst time arrives, the existing process is preempted.
  • 77.
  • 78. 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 FCFS manner. Priority can be decided based on memory requirements, time requirements or any other resource requirement.
  • 79.
  • 80. Round Robin(RR) Scheduling A fixed time is allotted to each process, called quantum, for execution. Once a process is executed for given time period that process is preemptied and other process executes for given time period. Context switching is used to save states of preemptied processes.
  • 81.
  • 82. Multilevel Queue Scheduling Another class of scheduling algorithms has been created for situations in which processes are easily classified into different groups. For example: A common division is made between foreground(or interactive) processes and background (or batch) processes. These two types of processes have different response-time requirements, and so might have different scheduling needs. In addition, foreground processes may have priority over background processes. A multi-level queue scheduling algorithm partitions the ready queue into several separate queues. The processes are permanently assigned to one queue, generally based on some property of the process, such as memory size, process priority, or process type. Each queue has its own scheduling algorithm. For example: separate queues might be used for foreground and background processes. The foreground queue might be scheduled by Round Robin algorithm, while the background queue is scheduled by an FCFS algorithm. In addition, there must be scheduling among the queues, which is commonly implemented as fixed-priority preemptive scheduling. For example: The foreground queue may have absolute priority over the background queue.
  • 83. Let us consider an example of a multilevel queue- scheduling algorithm with five queues: System Processes Interactive Processes Interactive Editing Processes Batch Processes Student Processes Each queue has absolute priority over lower-priority queues. No process in the batch queue, for example, could run unless the queues for system processes, interactive processes, and interactive editing processes were all empty. If an interactive editing process entered the ready queue while a batch process was running, the batch process will be preempted.
  • 84.
  • 85. Multilevel Feedback Queue Scheduling In a multilevel queue-scheduling algorithm, processes are permanently assigned to a queue on entry to the system. Processes do not move between queues. This setup has the advantage of low scheduling overhead, but the disadvantage of being inflexible. Multilevel feedback queue scheduling, however, allows a process to move between queues. The idea is to separate processes with different CPU- burst characteristics. If a process uses too much CPU time, it will be moved to a lower-priority queue. Similarly, a process that waits too long in a lower-priority queue may be moved to a higher- priority queue. This form of aging prevents starvation.
  • 86. An example of a multilevel feedback queue can be seen in the below figure.
  • 87. In general, a multilevel feedback queue scheduler is defined by the following parameters: The number of queues. The scheduling algorithm for each queue. The method used to determine when to upgrade a process to a higher-priority queue. The method used to determine when to demote a process to a lower-priority queue. The method used to determine which queue a process will enter when that process needs service. The definition of a multilevel feedback queue scheduler makes it the most general CPU-scheduling algorithm. It can be configured to match a specific system under design. Unfortunately, it also requires some means of selecting values for all the parameters to define the best scheduler. Although a multilevel feedback queue is the most general scheme, it is also the most complex.