0% found this document useful (0 votes)
4 views24 pages

Unit 2

This document provides an overview of processes and threads in operating systems, defining a process as a program in execution that can be divided into four sections: stack, heap, text, and data. It explains the process life cycle, the role of the Process Control Block (PCB), and the differences between user-level and kernel-level threads, emphasizing the benefits of multithreading for performance and responsiveness. Additionally, it discusses process scheduling, including types of schedulers and the importance of managing process states and queues.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views24 pages

Unit 2

This document provides an overview of processes and threads in operating systems, defining a process as a program in execution that can be divided into four sections: stack, heap, text, and data. It explains the process life cycle, the role of the Process Control Block (PCB), and the differences between user-level and kernel-level threads, emphasizing the benefits of multithreading for performance and responsiveness. Additionally, it discusses process scheduling, including types of schedulers and the importance of managing process states and queues.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT:2

Process:A process is basically a program in execution. The execution of a process


must progress in a sequential fashion.A process is defined as an entity which
represents the basic unit of work to be implemented in the [Link] put it in
simple terms, we write our computer programs in a text file and when we execute
this program, it becomes a process which performs all the tasks mentioned in the
program.

When a program is loaded into the memory and it becomes a process, it can be
divided into four sections ─ stack, heap, text and data. The following image shows
a simplified layout of a process inside main memory –

S.N. Component & Description

Stack
1 The process Stack contains the temporary data such as method/function
parameters, return address and local variables.

Heap
2
This is dynamically allocated memory to a process during its run time.

Text
3 This includes the current activity represented by the value of Program Counter and
the contents of the processor's registers.

Data
4
This section contains the global and static variables.
Program:A program is a piece of code which may be a single line
or millions of lines. A computer program is usually written by a
computer programmer in a programming language. For example,
here is a simple program written in C programming language −
#include <stdio.h>

int main() {
printf("Hello, World! \n");
return 0;
}

A computer program is a collection of instructions that performs a specific


task when executed by a computer. When we compare a program with a
process, we can conclude that a process is a dynamic instance of a computer
program.

A part of a computer program that performs a well-defined task is known as


an algorithm. A collection of computer programs, libraries and related data
are referred to as a software.

Process Life Cycle:

When a process executes, it passes through different states.


These stages may differ in different operating systems, and the
names of these states are also not standardized.

In general, a process can have one of the following five states at


a time.

S.N. State & Description


Start
1 This is the initial state when a process is first started/created.

Ready
The process is waiting to be assigned to a processor. Ready processes are
2 waiting to have the processor allocated to them by the operating system so
that they can run. Process may come into this state after Start state or while
running it by but interrupted by the scheduler to assign CPU to some other
process.

Running
3 Once the process has been assigned to a processor by the OS scheduler, the
process state is set to running and the processor executes its instructions.
Waiting
4 Process moves into the waiting state if it needs to wait for a resource, such
as waiting for user input, or waiting for a file to become available.
Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating
5 system, it is moved to the terminated state where it waits to be removed
from main memory.

Process Control Block (PCB):A Process Control Block is a data structure


maintained by the Operating System for every process. The PCB is identified by an
integer process ID (PID). A PCB keeps all the information needed to keep track of a
process as listed below in the table –

S.N. Information & Description


Process State
1 The current state of the process i.e., whether it is ready, running,
waiting, or whatever.
Process privileges
2
This is required to allow/disallow access to system resources.
Process ID
3
Unique identification for each of the process in the operating system.
Pointer
4
A pointer to parent process.
Program Counter
5 Program Counter is a pointer to the address of the next instruction to be
executed for this process.
CPU registers
6 Various CPU registers where process need to be stored for execution
for running state.
CPU Scheduling Information
7 Process priority and other scheduling information which is required to
schedule the process.
Memory management information
8 This includes the information of page table, memory limits, Segment
table depending on memory used by the operating system.
Accounting information
9 This includes the amount of CPU used for process execution, time
limits, execution ID etc.
IO status information
10
This includes a list of I/O devices allocated to the process.

The architecture of a PCB is completely dependent on Operating System and may


contain different information in different operating systems. Here is a simplified
diagram of a PCB –

The PCB is maintained for a process throughout its lifetime, and is deleted once the
process terminates.
Thread in Operating System

A thread is a single sequence stream within a process. Threads are also
called lightweight processes as they possess some of the properties of processes.
Each thread belongs to exactly one process.
 In an operating system that supports multithreading, the process can consist of many
threads. But threads can be effective only if the CPU is more than 1 otherwise two
threads have to context switch for that single CPU.
 All threads belonging to the same process share – code section, data section, and OS
resources (e.g. open files and signals)
 But each thread has its own (thread control block) – thread ID, program counter,
register set, and a stack
 Any operating system process can execute a thread. we can say that single process can
have multiple threads.
Why Do We Need Thread?
 Threads run in concurrent manner that improves the application performance. Each
such thread has its own CPU state and stack, but they share the address space of the
process and the environment. For example, when we work on Microsoft
Word or Google Docs, we notice that while we are typing, multiple things happen
together (formatting is applied, page is changed and auto save happens).
 Threads can share common data so they do not need to use inter-process
communication. Like the processes, threads also have states like ready, executing,
blocked, etc.
 Priority can be assigned to the threads just like the process, and the highest priority
thread is scheduled first.
 Each thread has its own Thread Control Block (TCB). Like the process, a context
switch occurs for the thread, and register contents are saved in (TCB). As threads
share the same address space and resources, synchronization is also required for the
various activities of the thread.
Components of Threads
These are the basic components of the Operating System.
 Stack Space: Stores local variables, function calls, and return addresses specific to the
thread.
 Register Set: Hold temporary data and intermediate results for the thread’s execution.
 Program Counter: Tracks the current instruction being executed by the thread.
Types of Thread in Operating System
Threads are of two types. These are described below.
 User Level Thread
 Kernel Level Thread
Threads

1. User Level Thread


User Level Thread is a type of thread that is not created using system calls. The kernel
has no work in the management of user-level threads. User-level threads can be easily
implemented by the user. In case when user-level threads are single-handed processes,
kernel-level thread manages them. Let’s look at the advantages and disadvantages of
User-Level Thread.
Advantages of User-Level Threads
 Implementation of the User-Level Thread is easier than Kernel Level Thread.
 Context Switch Time is less in User Level Thread.
 User-Level Thread is more efficient than Kernel-Level Thread.
 Because of the presence of only Program Counter, Register Set, and Stack Space, it
has a simple representation.
Disadvantages of User-Level Threads
 The operating system is unaware of user-level threads, so kernel-level optimizations,
like load balancing across CPUs, are not utilized.
 If a user-level thread makes a blocking system call, the entire process (and all its
threads) is blocked, reducing efficiency.
 User-level thread scheduling is managed by the application, which can become
complex and may not be as optimized as kernel-level scheduling.

2. Kernel Level Threads
A kernel Level Thread is a type of thread that can recognize the Operating system easily.
Kernel Level Threads has its own thread table where it keeps track of the system. The
operating System Kernel helps in managing threads. Kernel Threads have somehow
longer context switching time. Kernel helps in the management of threads.
Advantages of Kernel-Level Threads
 Kernel-level threads can run on multiple processors or cores simultaneously, enabling
better utilization of multicore systems.
 The kernel is aware of all threads, allowing it to manage and schedule them effectively
across available resources.
 Applications that block frequency are to be handled by the Kernel-Level Threads.
 The kernel can distribute threads across CPUs, ensuring optimal load balancing and
system performance.
Disadvantages of Kernel-Level threads
 Context switching between kernel-level threads is slower compared to user-level
threads because it requires mode switching between user and kernel space.
 Managing kernel-level threads involves frequent system calls and kernel interactions,
leading to increased CPU overhead.
 A large number of threads may overload the kernel scheduler, leading to potential
performance degradation in systems with many threads.
 Implementation of this type of thread is a little more complex than a user-level thread.
For more, refer to the Difference Between User-Level Thread and Kernel-Level
Thread.

Difference Between Process and Thread

The primary difference is that threads within the same process run in a shared memory
space, while processes run in separate memory spaces. Threads are not independent of
one another like processes are, and as a result, threads share with other threads their code
section, data section, and OS resources (like open files and signals). But, like a process, a
thread has its own program counter (PC), register set, and stack space.
For more, refer to Difference Between Process and Thread.
What is Multi-Threading?
A thread is also known as a lightweight process. The idea is to achieve parallelism by
dividing a process into multiple threads. For example, in a browser, multiple tabs can be
different threads. MS Word uses multiple threads: one thread to format the text, another
thread to process inputs, etc. More advantages of multithreading are discussed below.
Multithreading is a technique used in operating systems to improve the performance and
responsiveness of computer systems. Multithreading allows multiple threads (i.e.,
lightweight processes) to share the same resources of a single process, such as the
CPU, memory, and I/O devices.
Single Threaded vs Multi-threaded Process

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.

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 at a time and the loaded process shares the CPU using time
multiplexing Multithreading can be done without OS support, as seen in Java’s
multithreading model. In Java, threads are implemented using the Java Virtual Machine
(JVM), which provides its own thread management. These threads, also called user-level
threads, are managed independently of the underlying operating system.
Application itself manages the creation, scheduling, and execution of threads without
relying on the operating system’s kernel. The application contains a threading library that
handles thread creation, scheduling, and context switching. The operating system is
unaware of User-Level threads and treats the entire process as a single-threaded entity.
Benefits of Thread in Operating System

 Responsiveness: If the process is divided into multiple threads, if one thread completes its
execution, then its output can be immediately returned.
 Faster context switch: Context switch time between threads is lower compared to the
process context switch. Process context switching requires more overhead from the CPU.
 Effective utilization of multiprocessor system: If we have multiple threads in a single
process, then we can schedule multiple threads on multiple processors. This will make
process execution faster.
 Resource sharing: Resources like code, data, and files can be shared among all threads
within a process. Note: Stacks and registers can’t be shared among the threads. Each thread
has its own stack and registers.
 Communication: Communication between multiple threads is easier, as the threads share a
common address space. while in the process we have to follow some specific communication
techniques for communication between the two processes.
 Enhanced throughput of the system: If a process is divided into multiple threads, and each
thread function is considered as one job, then the number of jobs completed per unit of time is
increased, thus increasing the throughput of the system.

Definition
.Categories of Scheduling
There are two categories of scheduling:

1. 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.
2. 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; in the above diagram, it has been merged with the CPU.

Two-State Process Model


Two-state process model refers to running and non-running states which are
described below −

S.N. State & Description

Running
1 When a new process is created, it 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.
2 Queue is implemented by using linked list. Use of dispatcher is as
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.
Schedulers
Schedulers are special system software which handle process scheduling in various
ways. Their main task is to select the jobs to be submitted into the system and to
decide which process to run. Schedulers are of three types −

 Long-Term Scheduler
 Short-Term Scheduler
 Medium-Term Scheduler

Long 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 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.

On some systems, the long-term scheduler may not be available or minimal. Time-
sharing operating systems have no long term scheduler. When a process changes
the state from new to ready, then there is use of long-term scheduler.

Short Term Scheduler


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.
Medium Term Scheduler
Medium-term scheduling is a part of swapping. It removes the processes from the
memory. It reduces the degree of multiprogramming. The medium-term scheduler
is in-charge of handling the swapped out-processes.

A running process may become suspended if it makes an I/O request. A suspended


processes cannot make any progress towards completion. In this condition, to
remove the process from memory and make space for other processes, the
suspended process is moved to the secondary storage. This process is
called swapping, and the process is said to be swapped out or rolled out. Swapping
may be necessary to improve the process mix.

Comparison among Scheduler


S.N. Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

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

Speed is in between both


Speed is lesser than short Speed is fastest among
2 short and long term
term scheduler other two
scheduler.

It provides lesser
It controls the degree of It reduces the degree of
3 control over degree of
multiprogramming multiprogramming.
multiprogramming

It is almost absent or
It is also minimal in time It is a part of Time sharing
4 minimal in time sharing
sharing system systems.
system

It can re-introduce the


It selects processes from It selects those
process into memory and
5 pool and loads them into processes which are
execution can be
memory for execution ready to execute
continued.
CPU Scheduling in Operating Systems

CPU scheduling is a process used by the operating system to decide which task or process gets
to use the CPU at a particular time. This is important because a CPU can only handle one task at
a time, but there are usually many tasks that need to be processed. The following are different
purposes of a CPU scheduling time.
 Maximize the CPU utilization
 Minimize the response and waiting time of the process.
What is the Need for a CPU Scheduling Algorithm?
CPU scheduling is the process of deciding which process will own the CPU to use while another
process is suspended. The main function of CPU scheduling is to ensure that whenever the CPU
remains idle, the OS has at least selected one of the processes available in the ready-to-use line.
In Multiprogramming, if the long-term scheduler selects multiple I/O binding processes then
most of the time, the CPU remains idle. The function of an effective program is to improve
resource utilization.
Terminologies Used in CPU Scheduling
 Arrival Time: The time at which the process arrives in the ready queue.
 Completion Time: The time at which the process completes its execution.
 Burst Time: Time required by a process for CPU execution.
 Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time = Completion Time – Arrival Time
 Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time

Things to Take Care While Designing a CPU Scheduling Algorithm


Different CPU Scheduling algorithms have different structures and the choice of a particular
algorithm depends on a variety of factors.
 CPU Utilization: The main purpose of any CPU algorithm is to keep the CPU as busy as
possible. Theoretically, CPU usage can range from 0 to 100 but in a real-time system, it
varies from 40 to 90 percent depending on the system load.
 Throughput: The average CPU performance is the number of processes performed and
completed during each unit. This is called throughput. The output may vary depending on the
length or duration of the processes.
 Turn Round Time: For a particular process, the important conditions are how long it takes
to perform that process. The time elapsed from the time of process delivery to the time of
completion is known as the conversion time. Conversion time is the amount of time spent
waiting for memory access, waiting in line, using CPU, and waiting for I / O.
 Waiting Time: The Scheduling algorithm does not affect the time required to complete the
process once it has started performing. It only affects the waiting time of the process i.e. the
time spent in the waiting process in the ready queue.
 Response Time: In a collaborative system, turn around time is not the best option. The
process may produce something early and continue to computing the new results while the
previous results are released to the user. Therefore another method is the time taken in the
submission of the application process until the first response is issued. This measure is called
response time.
Different Types of CPU Scheduling Algorithms
There are mainly two types of scheduling methods:
 Preemptive Scheduling: Preemptive scheduling is used when a process switches from
running state to ready state or from the waiting state to the ready state.
 Non-Preemptive Scheduling: Non-Preemptive scheduling is used when a process terminates
, or when a process switches from running state to waiting state.

CPU Scheduling

CPU Scheduling Algorithms


Let us now learn about these CPU scheduling algorithms in operating systems one by one:
 FCFS – First Come, First Serve
 SJF – Shortest Job First
 SRTF – Shortest Remaining Time First
 Round Robin
 Priority Scheduling
 HRRN – Highest Response Ratio Next
 Multiple Queue Scheduling
 Multilevel Feedback Queue Scheduling
Comparison of CPU Scheduling Algorithms
Here is a brief comparison between different CPU scheduling algorithms:
Average
Algorithm waiting time
Allocation Complexity (AWT) Preemption Starvation Performance

According Simple and


to the easy to Large. Slow
No No
arrival time implement performance
FCFS
of the
Average
Algorithm waiting time
Allocation Complexity (AWT) Preemption Starvation Performance

processes,
the CPU is
allocated.

Based on
More Minimum
the lowest Smaller
complex Average
CPU burst than FCFS No Yes
than FCFS Waiting
SJF time (BT). Time

Same as SJF
the
Depending
allocation
on some
of the CPU The
More measures
is based on preference
complex e.g., arrival Yes Yes is given to
the lowest
than FCFS time, the short
CPU burst
process jobs
time (BT).
size, etc
But it is
SRTF preemptive.

According
to the order The
Large as
of the complexity Each
compared
process depends on process has
to SJF and
arrives with Time Yes No given a
Priority fairly fixed
fixed time Quantum
scheduling. time
quantum size
RR (TQ)
Average
Algorithm waiting time
Allocation Complexity (AWT) Preemption Starvation Performance

According
to the
priority. This type is Well
Smaller performance
The bigger less Yes Yes but contain
than FCFS
priority task complex a starvation
Priority Pre- executes problem
emptive first

According
to the
This type is
priority
less
with Preemptive Most
complex
monitoring Smaller beneficial
than No Yes
the new than FCFS with batch
Priority systems
incoming
preemptive
Priority non- higher
preemptive priority jobs

According
to the More
process complex Good
that resides than the Smaller performance
in the priority than FCFS No Yes but contain
bigger scheduling a starvation
problem
queue algorithms
MLQ priority

According It is the Smaller Good


MFLQ No No
to the most than all performance
Average
Algorithm waiting time
Allocation Complexity (AWT) Preemption Starvation Performance

process of a Complex scheduling


bigger but its types in
priority complexity many cases
queue. rate
depends on
the TQ size

Questions for Practice


Question: Which of the following is false about SJF?
S1: It causes minimum average waiting time
S2: It can cause starvation
(A) Only S1
(B) Only S2
(C) Both S1 and S2
(D) Neither S1 nor S2
Answer: (D) S1 is true SJF will always give minimum average waiting time. S2 is true SJF can
cause starvation.
Question: Consider the following table of arrival time and burst time for three processes P0, P1 and
P2.

Process Arrival time Burst Time

P0 0 ms 9 ms

P1 1 ms 4 ms

P2 2 ms 9 ms

The pre-emptive shortest job first scheduling algorithm is used. Scheduling is carried out
only at arrival or completion of processes. What is the average waiting time for the three
processes?
(A) 5.0 ms
(B) 4.33 ms
(C) 6.33
(D) 7.33
Solution: (A)
Process P0 is allocated processor at 0 ms as there is no other process in the ready queue. P0 is
preempted after 1 ms as P1 arrives at 1 ms and burst time for P1 is less than remaining time of
P0. P1 runs for 4ms. P2 arrived at 2 ms but P1 continued as burst time of P2 is longer than P1.
After P1 completes, P0 is scheduled again as the remaining time for P0 is less than the burst time
of P2. P0 waits for 4 ms, P1 waits for 0 ms and P2 waits for 11 ms. So average waiting time is
(0+4+11)/3 = 5.
Question: Consider the following set of processes, with the arrival times and the CPU-burst times
given in milliseconds.

Process Arrival time Burst Time

P1 0 ms 5 ms

P2 1 ms 3 ms

P3 2 ms 3 ms

P4 4 ms 1 ms

What is the average turnaround time for these processes with the preemptive Shortest
Remaining Processing Time First algorithm ?
(A) 5.50
(B) 5.75
(C) 6.00
(D) 6.25
Answer: (A)
Solution: The following is Gantt Chart of execution

P1 P2 P4 P3 P1

1 4 5 8 12

Turn Around Time = Completion Time – Arrival Time Avg Turn Around Time = (12 + 3 + 6+
1)/4 = 5.50
Question: An operating system uses the Shortest Remaining Time First (SRTF) process scheduling
algorithm. Consider the arrival times and execution times for the following processes:

Process Arrival time Burst Time

P1 20 ms 0 ms

P2 25 ms 15 ms

P3 10 ms 30 ms

P4 15 ms 45 ms

What is the total waiting time for process P2?


(A) 5
(B) 15
(C) 40
(D) 55
Answer (B)
Solution: At time 0, P1 is the only process, P1 runs for 15 time units. At time 15, P2 arrives, but
P1 has the shortest remaining time. So P1 continues for 5 more time units. At time 20, P2 is the
only process. So it runs for 10 time units At time 30, P3 is the shortest remaining time process.
So it runs for 10 time units At time 40, P2 runs as it is the only process. P2 runs for 5 time units.
At time 45, P3 arrives, but P2 has the shortest remaining time. So P2 continues for 10 more time
units. P2 completes its execution at time 55.
Total waiting time for P2
= Completion time – (Arrival time + Execution time)
= 55 – (15 + 25)
= 15
Preemptive and Non-Preemptive Scheduling

In operating systems, scheduling is the method by which processes are given
access the CPU. Efficient scheduling is essential for optimal system performance
and user experience. There are two primary types of CPU scheduling: preemptive
and non-preemptive.
Understanding the differences between preemptive and non-preemptive scheduling
helps in designing and choosing the right scheduling algorithms for various types
of operating systems.
Preemptive Scheduling
The operating system can interrupt or preempt a running process to allocate CPU
time to another process, typically based on priority or time-sharing policies.
Mainly a process is switched from the running state to the ready state. Algorithms
based on preemptive scheduling are Round Robin (RR) , Shortest Remaining Time
First (SRTF) , Priority (preemptive version) , etc.
In the following example P2 is preempted at time 1 due to arrival of a higher
priority process.

Preemptive Scheduling

Advantages of Preemptive Scheduling


 Because a process may not monopolize the processor, it is a more reliable method and
does not cause denial of service attack.
 Each preemption occurrence prevents the completion of ongoing tas s.
 The average response time is improved. Utilizing this method in a multi-programming
environment is more advantageous.
 Most of the modern operating systems (Window, Linux and macOS) implement
Preemptive Scheduling.
Disadvantages of Preemptive Scheduling
 More Complex to implement in Operating Systems.
 Suspending the running process, change the context, and dispatch the new incoming
process all take more time.
 Might cause starvation : A low-priority process might be preempted again and again if
multiple high-priority processes arrive.
 Causes Concurrency Problems as processes can be stopped when they were accessing
shared memory (or variables) or resources.
Non-Preemptive Scheduling
In non-preemptive scheduling, a running process cannot be interrupted by the
operating system; it voluntarily relinquishes control of the CPU. In this scheduling,
once the resources (CPU cycles) are allocated to a process, the process holds the
CPU till it gets terminated or reaches a waiting state.
Algorithms based on non-preemptive scheduling are: First Come First
Serve, Shortest Job First (SJF basically non preemptive) and Priority
(nonpreemptive version) , etc.
Below is the table and Gantt Chart according to the First Come FIrst Serve
(FCFS) Algorithm: We can notice that every process finishes execution once it
gets CPU.

Advantages of Non-Preemptive Scheduling


 It is easy to implement in an operating system. It was used in Windows 3.11 and early
macOS.
 It has a minimal scheduling burden.
 Less computational resources are used.
Disadvantages of Non-Preemptive Scheduling
 It is open to denial of service attack. A malicious process can take CPU forever.
 Since we cannot implement round robin, the average response time becomes less.
Differences Between Preemptive and Non-Preemptive
Scheduling
 In Preemptive Scheduling, there is the overhead of switching the process from the
ready state to the running state, vise-verse, and maintaining the ready queue. Whereas
in the case of non-preemptive scheduling has no overhead of switching the process
from running state to ready state.
 Preemptive scheduling attains flexibility by allowing the critical processes to access
the CPU as they arrive in the ready queue, no matter what process is executing
currently. Non-preemptive scheduling is called rigid as even if a critical process enters
the ready queue the process running CPU is not disturbed.
 Preemptive Scheduling has to maintain the integrity of shared data that’s why it is cost
associative which is not the case with Non-preemptive Scheduling.

PREEMPTIVE NON-PREEMPTIVE
Parameter SCHEDULING SCHEDULING

Once resources(CPU Cycle)


In this resources(CPU
are allocated to a process,
Cycle) are allocated to a
the process holds it till it
process for a limited
completes its burst time or
time.
Basic switches to waiting state

Process can not be


Process can be interrupted until it
interrupted in between. terminates itself or its time
Interrupt is up

If a process having high If a process with a long


priority frequently burst time is running CPU,
arrives in the ready then later coming process
queue, a low priority with less CPU burst time
Starvation process may starve may starve
PREEMPTIVE NON-PREEMPTIVE
Parameter SCHEDULING SCHEDULING

It has overheads of
It does not have overheads
Overhead scheduling the processes

Flexibility flexible Rigid

Cost Cost associated No cost associated

Preemptive scheduling Non-preemptive scheduling


Response Time response time is less response time is high

Decisions are made by Decisions are made by the


the scheduler and are process itself and the OS
based on priority and just follows the process’s
Decision making time slice allocation instructions

The OS has greater


The OS has less control over
control over the
the scheduling of processes
Process control scheduling of processes

Higher overhead due to Lower overhead since


frequent context context switching is less
Overhead switching frequent
PREEMPTIVE NON-PREEMPTIVE
Parameter SCHEDULING SCHEDULING

More as a process might


be preempted when it Less as a process is never
Concurrency was accessing a shared preempted.
Overhead resource.

Examples of preemptive Examples of non-


scheduling are Round preemptive scheduling are
Robin and Shortest First Come First Serve and
Examples Remaining Time First Shortest Job First

You might also like