Process scheduling-module3
Process scheduling-module3
UNIVERSITY
GROUP :2
AREA OF CONCENTRATION : Process Scheduling, Schedulers and Queues
GROUP MEMBERS
Cover page
PROCESS SCHEDULING
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.
Categories of Scheduling
Scheduling falls into one of two categories:
• Non-Preemptive: In this case, a process’s resource cannot be taken
before the process has finished running. When a running process finishes and
transitions to a waiting state, resources are switched. The switching of
resources occurs when the running process terminates and moves to a waiting
state.
2|Page
• Preemptive: In this case, the OS can switch a process from running state
to ready state. This switching happens because the CPU may give other
processes priority and substitute the currently active process for the higher
priority process.
Hint: Preemptive scheduling allows the operating system to interrupt a running process
to execute a higher priority process, while non-preemptive scheduling requires a process
to finish execution before another can start.
Process schedulers
Process schedulers are the essential parts of operating system that manage how the
CPU handles multiple tasks or processes. They ensure that processes are executed
efficiently, making the best use of CPU resources and maintaining system
responsiveness. By choosing the right process to run at the right time, schedulers help
optimize overall system performance, improve user experience, and ensure fair access
to CPU resources among competing processes. Their main task is to select the jobs to
be submitted into the system and to decide which process to run.
Types of process schedulers
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler
It is also called a job scheduler. A long-term scheduler determines which programs are
admitted to the system for processing. It selects processes from the queue and loads
them into memory for execution. Process loads into the memory for CPU scheduling.
The primary objective of the job scheduler is to provide a balanced mix of jobs, such as
I/O bound and processor bound. It also controls the degree of multiprogramming. If the
3|Page
degree of multiprogramming is stable, then the average rate of process creation must be
equal to the average departure rate of processes leaving the system.
In some systems, the long-term scheduler might not even exist. For example, in time-
sharing systems like Microsoft Windows, there is usually no long-term scheduler.
Instead, every new process is directly added to memory for the short-term scheduler to
handle.
Slowest among the three (that is why called long term).
It is also called as CPU scheduler. Its main objective is to increase system performance
in accordance with the chosen set of criteria. It is the change of ready state to running
state of the process. CPU scheduler selects a process among the processes that are ready
to execute and allocates CPU to one of them.
Short-term schedulers, also known as dispatchers, make the decision of which process to
execute next. Short-term schedulers are faster than long-term schedulers.
Hint: The dispatcher is responsible for loading the process selected by the Short-term
scheduler on the CPU (Ready to Running State).
Structure
4|Page
Medium Term Scheduler
Structure
5|Page
Advantages of process scheduling
By selecting which processes run next, the operating system can optimize CPU usage
and prevent idle time.
NB; CPU optimization is the process of improving the efficiency of a computer's Central
Processing Unit (CPU) i.e. buffer size as this helps to lower the CPU usage etc. This
can help applications and systems run faster and use fewer resources.
• Improved responsiveness
Allows for quick switching between processes, giving the appearance of simultaneous
execution and providing better responsiveness for interactive tasks like typing or
clicking.
• Fairness
Scheduling algorithms can prioritize processes based on factors like arrival time or
priority, ensuring that all processes get a chance to execute.
NB; A scheduling algorithm in an operating system (OS) is a set of rules that determines
which process gets access to the CPU next, essentially deciding how much CPU time is
allocated to each process and when, aiming to optimize system performance by balancing
factors like wait time, turnaround time, and throughput. They decide which process from
the ready queue should be executed next based on specific criteria like arrival time,
priority, or estimated execution time.
• Multitasking capability
• Flexibility
Different scheduling algorithms can be used depending on the workload, like
prioritizing short bursts for interactive tasks or longer processes for batch jobs.
6|Page
Disadvantages of process scheduling
Switching between processes requires saving and restoring the state of each process,
which can consume CPU cycles and slow down system performance.
Note: In an operating system (OS), context switching refers to the process where
the CPU temporarily saves the state of a currently running process, allowing it to switch
to another process and execute its tasks, essentially enabling multitasking by giving
the appearance of multiple programs running simultaneously on a single CPU, it
involves storing the current process's state (like register values) and loading the state
of the new process to be executed, effectively pausing one process to resume another
later.
• Starvation potential
If a scheduling algorithm doesn't manage priorities well, a low priority process might
wait indefinitely for a high priority process to finish, leading to starvation.
• Complexity
Depending on the chosen algorithm, some processes might experience long waiting
times if they are placed behind longer running processes.
7|Page
Process scheduling queue
• Job queue − This queue keeps all the processes in the system. For example, a
batch system where multiple jobs are waiting to be executed.
• 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. For
example, in multitasking system, processes that are not currently executing but
are ready to be scheduled.
• Device/blocked/waiting queue − The processes which are blocked due to
unavailability of an I/O device constitute this queue. For example, a process
waiting for user input or disk read/write operation.
Structure of queues
8|Page
Two-State Process Model
Two-state process model refers to running and non-running states which are described
below −
Running
When a new process is created, it
1
enters into the system as in the
running state.
Not Running
Processes that are not running are
kept in queue, waiting for their turn
to execute. Each entry in the queue
is a pointer to a particular process.
Queue is implemented by using
linked list. Use of dispatcher is as
2 follows. When a process is
interrupted, that process is
transferred in the waiting queue. If
the process has completed or
aborted, the process is discarded. In
either case, the dispatcher then
selects a process from the queue to
execute.
9|Page
Context Switching
Using this technique, a context switcher enables multiple processes to share a single CPU.
Context switching is an essential part of a multitasking operating system features.
When the scheduler switches the CPU from executing one process to execute another,
the state from the current running process is stored into the process control block. After
this, the state for the process to run next is loaded from its own PCB and used to set the
PC, registers, etc. At that point, the second process can start executing.
Hint: PCB stands for Process Control Block, it refers to the dedicated data structure that
stores all essential information about the running process, including its current state,
program counter, register values, memory usage, memory allocation and I/O status.
Structure
10 | P a g e
Context switches are computationally intensive since register and memory state must be
saved and restored. To avoid the amount of context switching time, some hardware
systems employ two or more sets of processor registers. When the process is switched,
the following information is stored for later use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information
Note:
11 | P a g e
References
Silberschatz, Galvin, and Gagne (Operating System Concepts, 9th Edition, 2012):
https://www.geeksforgeeks.org/process-schedulers-in-operating-system/
https://www.tutorialspoint.com/operating_system/os_process_scheduling.htm
12 | P a g e