Process Management
Unit 2
System Programming and Operating System
What is Process?
A process in an operating system (OS) is a program that is currently being executed.
Program under execution is also known as Process.
It is a sequence of instructions that are executed in a specific order.
A process includes the program code, its current activity, and the data it manipulates.
https://youtu.be/aytWaG4mEJI?si=VH9BsdSmYEf45_vR
Process States
•New (Create): In this step, the process is about to be created but not yet created. It is the program that is present
in secondary memory that will be picked up by OS to create the process.
•Ready: New -> Ready to run. After the creation of a process, the process enters the ready state i.e. the process is
loaded into the main memory. The process here is ready to run and is waiting to get the CPU time for its
execution. Processes that are ready for execution by the CPU are maintained in a queue called ready queue for
ready processes.
•Run: The process is chosen from the ready queue by the CPU for execution and the instructions within the
process are executed by any one of the available CPU cores.
•Blocked or Wait: Whenever the process requests access to I/O or needs input from the user or needs access to a
critical region(the lock for which is already acquired) it enters the blocked or waits for the state. The process
continues to wait in the main memory and does not require CPU. Once the I/O operation is completed the process
goes to the ready state.
•Terminated or Completed: Process is killed as well as PCB is deleted. The resources allocated to the process
will be released or deallocated.
How does a process move between different states in an operating
system?
A process can move between different states in an operating system based on its execution status and
resource availability. Here are some examples of how a process can move between different states:
•New to ready: When a process is created, it is in a new state. It moves to the ready state when the
operating system has allocated resources to it and it is ready to be executed.
•Ready to running: When the CPU becomes available, the operating system selects a process from
the ready queue depending on various scheduling algorithms and moves it to the running state.
•Running to blocked: When a process needs to wait for an event to occur (I/O operation or system
call), it moves to the blocked state. For example, if a process needs to wait for user input, it moves to
the blocked state until the user provides the input.
• Running to ready: When a running process is preempted by the operating system, it moves
to the ready state. For example, if a higher-priority process becomes ready, the operating
system may preempt the running process and move it to the ready state.
• Blocked to ready: When the event a blocked process was waiting for occurs, the process
moves to the ready state. For example, if a process was waiting for user input and the input
is provided, it moves to the ready state.
• Running to terminated: When a process completes its execution or is terminated by the
operating system, it moves to the terminated state.
PCB Process Control Block
Process Control Block is a data structure that contains information of the process related to it.
The process control block is also known as a task control block, entry of the process table, etc.
The following are the data items −
Process State: This specifies the process state i.e. new, ready, running, waiting
or terminated.
Process Number: This shows the number of the particular process.
Program Counter: This contains the address of the next instruction that needs
to be executed in the process.
Registers: This specifies the registers that are used by the process. They may
include accumulators, index registers, stack pointers, general purpose
registers etc.
List of Open Files: These are the different files that are associated with the
process.
CPU Scheduling Information: The process priority, pointers to scheduling
queues etc. is the CPU scheduling information that is contained in the PCB. This
may also include any other scheduling parameters.
Memory Management Information: The memory management information
includes the page tables or the segment tables depending on the memory system
used. It also contains the value of the base registers, limit registers etc.
I/O Status Information: This information includes the list of I/O devices used by
the process, the list of files etc.
Accounting information: The time limits, account numbers, amount
of CPU used, process numbers etc. are all a part of the PCB accounting
information.
Location of the Process Control Block: The process control block is kept in a
memory area that is protected from the normal user access. This is done because
it contains important process information. Some of the operating systems place
the PCB at the beginning of the kernel stack for the process as it is a safe
location.
What is Process Scheduling?
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 based on a particular strategy.
Process scheduling is an essential part of a Multiprogramming operating system. Such operating systems allow
more than one process to be loaded into the executable memory at a time and the loaded process shares the CPU
using time multiplexing.
Queuing Diagram for Process Scheduling:
Scheduler
A scheduler in an operating system is a component that decides which process or thread gets
access to the CPU or other system resources at any given time. It plays a crucial role in process
management by efficiently allocating resources to ensure optimal system performance and
responsiveness.
Think of a scheduler as a traffic officer at a busy intersection. The officer decides which cars
(processes) can move, ensuring that traffic flows smoothly and no single lane (process)
monopolizes the road (CPU).
https://youtu.be/pro8cU5Uzdg?si=ojwnFWQULuKVhg_9
Types of Schedulers
Long-term – performance: Decides how many processes should be made to stay in the ready state.
This decides the degree of multiprogramming.
Once a decision is taken it lasts for a long time which also indicates that it runs infrequently. Hence it is
called a long-term scheduler.
Short-term – Context switching time: Short-term scheduler will decide which process is to be executed
next and then it will call the dispatcher.
A dispatcher is a software that moves the process from ready to run and vice versa.
In other words, it is context switching. It runs frequently. Short-term scheduler is also called CPU
scheduler.
Medium-term – Swapping time: Suspension decision is taken by the medium-term scheduler.
The medium-term scheduler is used for swapping which is moving the process from main memory to
secondary and vice versa.
The swapping is done to reduce degree of multiprogramming.
Difference between Short-Term, Medium term, and Long-Term Schedulers:
Basis Short-Term Scheduler Medium-term Scheduler Long-Term Scheduler
It is also called a process swapping
1. Alternate Name It is also called a CPU scheduler. It is also called a job scheduler.
scheduler.
2. Degree in It provides lesser control over the It reduces the control over the degree of It controls the degree of
programming degree of multiprogramming. multiprogramming. multiprogramming.
The speed of the short-term scheduler The speed of a long-term term
Speed of medium scheduler between
3. Speed is very fast. scheduler is more than medium-term
the short-term and long-term scheduler
scheduler.
4. Usage in time-
It is minimal in the time-sharing It is almost absent or minimal in a
sharing system It is a part of the time-sharing system.
system. sharing system.
sharing system
It can reintroduce the from among the
It selects the processes from among the process into memory that executes and It selects processes from the pool and
5. Purpose
process that is ready to execute. its execution can be continued. loads them into memory for execution.
6. Process state Process state is ready to running Process state is not present Process state is new to ready.
Select that process, which is currently
7. Selection of Select a new process for a CPU quite Select a good process , mix of I/O
not need to load fully on RAM, so it
process frequently. bound and CPU bound.
swap it into swap partition.
Context Switching
Context switching is the process of shifting focus from one task to another, and
then back again.
It can also refer to the process of storing the state of a process so that it can be
reloaded when needed
PROCESS SCHEDULING:
The process scheduling is the activity of removing of the running process from the CPU
and the selection of another process on the basis of a particular strategy.
Process scheduling is an essential part of a Multiprogramming operating systems.
Such operating systems allow more than one process to be loaded into the executable
memory.
Categories of Scheduling
There are two categories of scheduling:
Non-preemptive: Here the resource can’t be taken from a process until the process completes
execution. The switching of resources occurs when the running process terminates and moves to a
waiting state.
Preemptive: Here the OS allocates the resources to a process for a fixed amount of time. During
resource allocation, the process switches from running state to ready state or from waiting state to
ready state. This switching occurs as the CPU may give priority to other processes and replace the
process with higher priority with the running process.
Process Scheduling Queues
The OS maintains all Process Control Blocks (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.
The Operating System maintains the following important process scheduling queues −
Job queue − This queue keeps all the processes in the system.
Ready queue − This queue keeps a set of all processes residing in main memory, ready and waiting to
execute. A new process is always put in this queue.
Device queues − The processes which are blocked due to unavailability of an I/O device constitute this
queue.
The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.). The OS
scheduler determines how to move processes between the ready and run queues which can only have one
entry per processor core on the system.
The Purpose of a Scheduling algorithm
There are various algorithms which are used by the Operating System to schedule the
processes on the processor in an efficient way.
Maximum CPU utilization
Fare allocation of CPU
Maximum throughput
Minimum turnaround time
Minimum waiting time
Minimum response time
https://youtu.be/OhUab3VakuE?si=7JjRhlSqra9KgbNn
Scheduling Criteria
First-Come First-Serve (FCFS) Scheduling
“Burst time refers to the
amount of time(in
miliseconds) a process
needs to execute on the
CPU.”
FCFS Scheduling (Cont.)
Shortest –Job First (SJF) Scheduling
Example of SJF
https://youtu.be/UlpgVptO5Gk?si=OwKXl3WrhdFziNEL
Priority Scheduling
Example of Priority Scheduling
Non-Preemptive Priority Scheduling and
Preemptive Priority Scheduling
Non-Preemptive Scheduling In this algorithm, if a new process of higher priority than the currently running
process arrives, then the currently executing process is not disturbed. Rather, the newly arrived process is put at
the head of the ready queue, i.e. according to its priority in the queue.
https://youtu.be/OSYGKeTIDLQ?si=KZsxublRPq25uBiX
Preemptive priority scheduling is a scheduling algorithm used in operating systems where the currently running
process can be interrupted (preempted) if a higher priority process arrives in the ready queue. This ensures that
critical tasks with higher priorities are executed without delay, even if a lower priority process is currently
running.
https://youtu.be/UC8KF3SAEUc?si=KEO2kspzQoKK2O8i
https://youtu.be/hQ5uZcBf8Bc?si=gEiOInXhuh4Rxqe5
Round Robin (RR)
Example of RR with Time Quantum =4
Multilevel Queue
https://youtu.be/_Q3MqdKoc
AI?si=hNHBwIVagymu2qK3
https://youtu.be/_Q3MqdKocAI?si=L9cbB4QD9ykkI4_z
Multilevel Queue Scheduling
Multilevel Feedback Queue
Example of Multilevel Feedback Queue
Assignment Questions:
1) What is scheduling? Compare short term scheduler with long term scheduler.
2) Draw and explain Round Robin Scheduling with the help of an example.
3) Consider the following set of processes with the length of the CPU burst time given in
milliseconds –
Process Burst Time Arrival Time
P1 3 3
P2 3 6
P3 4 0
P4 5 2
i) Draw Gantt chart using non preemptive Shortest Job First method.
ii) Calculate average Turnaround time & average Waiting time.
4)Which scheduler controls the degree of multiprogramming?
5) What is Turn-Around Time?
6) Consider the following set of processes with length of CPU Burst time
and arrival time in milliseconds.
Process Arrival Time Burst Time
P1 0 3
P2 2 6
P3 4 4
P4 6 5
P5 8 2
Calculate turn around time, waiting time, average waiting time and average
turn around time using preemptive SJF scheduling algorithm.
7) What is medium term scheduler.
8) Define Burst Time.
9) Calculate average turn around time and average waiting time for all set of processes using FCFS algorithm.
Processes Burst Time Arrival Time
P1 5 1
P2 6 0
P3 2 2
P4 4 0
10) Explain multilevel Feedback queue Algorithm.
11) What are the difference between Preemptive and Non-Preemptive Scheduling.