0% found this document useful (0 votes)
8 views20 pages

Process Management and Scheduling Overview

The document provides an overview of process management and scheduling in operating systems, detailing the definition of processes, their life cycle, and the role of process control blocks (PCBs). It discusses operations on processes such as creation, pre-emption, blocking, and termination, as well as the types of scheduling (preemptive and non-preemptive) and the various types of schedulers. Additionally, it outlines scheduling criteria and the importance of CPU utilization in managing multiple processes efficiently.

Uploaded by

sonusowmya934
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)
8 views20 pages

Process Management and Scheduling Overview

The document provides an overview of process management and scheduling in operating systems, detailing the definition of processes, their life cycle, and the role of process control blocks (PCBs). It discusses operations on processes such as creation, pre-emption, blocking, and termination, as well as the types of scheduling (preemptive and non-preemptive) and the various types of schedulers. Additionally, it outlines scheduling criteria and the importance of CPU utilization in managing multiple processes efficiently.

Uploaded by

sonusowmya934
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

PART A

Process Management:
Process Concept:
What is process?
1. A program is a set of instructions that perform a task on a computer.
2. Where a process is an instance of a program that is currently being executed by the
operating system.
3. A process is also defined as executing a program in main memory.
4. A process is created whenever a program is loaded into the main memory or whenever
a program is executed.
5. The process is terminated whenever a program completes its execution.
Process management:
• It generally refers to the management of processes within an os. The primary goal of
the process management is to allocate system resources efficiently.
• Multiple active processes can may share resources like memory and cpu and may
communicate with each other.
• So process management manages the single and multiple processes.
• Process management in an operating system (OS) is the process of managing
programmes that are running in the system. It involves creating, scheduling, and
terminating processes.
The list of functions under process management is:
1. Process creation
2. Process termination
3. Process waiting
4. Process scheduling
5. Inter process communication(IPC)
6. Fork a process
7. Block a process
8. Resume a process
9. Ready process
10. Delay a process

How a process does looks like in memory:


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.

1
• The stack contains temporary data- such as local variables, functions parameters, return
address.
• The heap is used for the dynamic memory allocation to a process during run time and
is managed via calls to new, delete, malloc, free, etc.
• The data section is made up the global and static variables.
• The text section is includes current activity represented by the value of a program
counter.

Process control block (PCB)/ Characteristics of a process:


• Process Control block is also called as task control block.
• It contains all the necessary information about a process, which is required by
os to manage and control the execution of process.
• PCB is an important data structure which is used by os.
• The main purpose of pcb is to enable the os to manage the multiple process
efficiently by keeping the track of each state of each process and allocates the
system resources.
• When a process is created then os creates a PCB.
• The following diagram shows the structure of PCB and which contains
information as follows

Process id
Process state
Program counter
Register
List of open files
CPU scheduling info
Accounting info
Process priority
PCB pointers
Process i/o status info
Memory management

2
1. Process id(Pid):
Unique identification for each of the process in the operating system.
Ex: P1, P2
2. Process state:
Specifies the current state of a process.
Ex: new state, ready state, running state, waiting state, terminate state , block state etc.
3. Program counter:
Program Counter is used to store the address of current process and address of the next
instruction to be executed.
4. Register:
It is also like program counter, used to save the state of a process, when it is not running.
5. List of open files:
The information contains a list of open files associated with a process.
6. CPU scheduling info:
Contains information about priority of a process, scheduling queues information,
scheduling parameters etc.
7. Accounting info:
This includes the amount of CPU and memory used for process execution, time limits,
execution ID etc.
8. Process priority:
The priority of a process is stored within its PCB data structure, allowing the operating
system's scheduler to easily access this information when deciding which process to
run next.
9. PCB pointers: this field contains the address of the next PCB, which is in ready state.
10. Process I/O status info: used to keep information of I/O devices used by the process.
11. Memory management: keep tracking of providing the memory to process, preventing
the unauthorized access to memory etc.

Life cycle of a process (or) states of the process:


A process is a program in the execution phase. The life cycle of a process refers to the various
stages that a process goes through from its creation to its termination.
In general, a process can have one of the following five states at a time. Here are the different
stages of a process life cycle:
1. New state
2. Ready state
3. Running state
4. Waiting state
5. Terminate state

3
i. New state:
It is initial state of a process. When a process is created, it is a new state. The
process is not yet ready to run in this state and is waiting for the operating system to
give it the green light. Long-term schedulers shift the process from a NEW state to a
READY state.
ii. Ready state:
After creation of processes it moves into a ready state now, where the processes
is ready for execution but waiting for CPU. The process is ready to be assigned to the
processor. Now the process is waiting in the ready queue to be picked up by the short-
term scheduler. The short-term scheduler selects one process from the READY state to
the RUNNING state.
iii. Running state:
Once the process is ready, it moves on to the running state, where it starts to
execute the instructions that were given to it. The running state is also where the process
consumes most of its CPU time.
iv. Waiting state:
If the process needs to stop running for some reason, it enters the waiting state.
This could be because
• It’s waiting for some input
• It’s waiting for a resource that’s not available yet.
• Some high-priority process comes in that need to be executed. Then the process
is suspended for some time and is put in a WAITING state. Till then next
process is given chance to get executed
v. Terminate state:
If the process needs to stop running for some reason, it enters the waiting state. This
could be because
• It’s waiting for some input
• It’s waiting for a resource that’s not available yet.
• Some high-priority process comes in that need to be executed.
• Then the process is suspended for some time and is put in a WAITING state.
Till then next process is given chance to get executed

4
Operation on Processes:
Refers to actions/activities performed on processes in an os. So operation on process
are important for functioning of os.
1. ProcessCreation
2. Process Pre-emption
3. Process Blocking
4. Process Termination

1. Process Creation:
• It is the mechanism by which a new process will be created.
• The process creation is performing with different operations:
1. Tree:
a. Parent process creates child process.
b. In which create another process that look like tree
2. Resource sharing:
a. Parent and child share all resource
b. Parent and child share no resources
3. Execution:
a. Parent and child execute concurrently
b. Parent will wait until child terminates.
4. Address space:
a. Child is the duplicate of process
b. Child has a program loaded into it

▪ Above diagram shows the flow of a process execution. Where the


parent process creates a child process by using fork() system call.
▪ Parent will wait until the child terminate first. Because the OS will not
support to parent termination first.

5
▪ So that’s why after creation of child, the parent will move into waiting
state by using wait() system call.
▪ So the child will move into a execution state, where the child process
starts the execution by using exec() system call.
▪ After completion of child execution the child will moves into
termination state, where process termination will happened by using
exit() system call.
▪ After that the parent will resumes the execution.

2. Process Pre-emption:
• pre-emption is an interruption mechanism.
• Main aim is to make available of cpu to all processes.

3. Process Blocking:
a process request for an i/o operation operating system move the process into blocked
state that means not allocate the CPU to it instead allocate CPU to remaining process.

4. Process Termination:

• Process execute last statements and ask os to delete it from the main memory by using
the exit() system call operation.
• Parent may terminate the execution of child by using abort() system call operation
• The parent terminate the child because child has executed the allocated resources
• The operating system does not allow the child to continue to parent terminated.

6
PART B
Process Scheduling:
Basic Concepts
• 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.
• Process Scheduling is an OS task that schedules processes of different states like ready,
waiting, and running.
• Process scheduling allows OS to allocate a time interval of CPU execution for each
process.
• Another important reason for using a process scheduling system is that it keeps the CPU
busy all the time.
• This allows you to get the minimum response time for programs.

CATEGORIES OF SCHEDULING
There are two categories of scheduling in the operating system. Below are the two
categories of scheduling. We will discuss each of them in detail.
1. Preemptive
2. Non-Preemptive

Let's understand each of them in detail:

7
1. Preemptive:
• In this scheduling, the OS allocates a resource to the process for a fixed time interval
• during resource allocation the process switching from running state to ready state or
from waiting state to ready state.
• So, that switching will happens because OS gives other processes a higher priority and
replaces the lower priority process with the higher priority.
• Where the OS interrupts the current process execution and allocates that CPU to another
process based on priority. In this case OS can interrupt the process execution at any
time.

2. Non-Preemptive :
• In this, once the resource is allocated to a process, it cannot be changed.
• The resource cannot be withdrawn from a process in non-preemptive until the process
has completed execution.
• After the completion of execution, where the process submits a CPU voluntarily.
• Where the OS can’t interrupt the process execution.

Process scheduling queues:


• All the PCBs are maintained and arranged in Process Scheduling Queues by the
Operating System .
• the OS has a different clue for its process state
• and all the PCB in the same execution state are put in same process queue.
• When the process state changes its PCB is unbound from current queue and transfer to
new state queue.

Types of queues:
1. job queue(secondary memory)
2. ready queue(main memory)
3. device queue

I. job queue (secondary memory):


• All the processes will be stored in secondary storage.
• Stores all the process that are in the system i.e waiting for execution.
• This queue keeps all the process loading into main memory and those
process are kept in ready for execution.
• Long term scheduler picks a process from job queue and moves to ready
queue

ii. Ready queue (Main Memory) :


• Here the processes will be loaded into the main memory.
• Used to store all the processors which are ready for execution.

8
• Short Term Scheduler picks a process from Ready Queue and moves the
selected process to running state.

iii. Waiting Queue or Device Queues (In Main Memory) :


• Device queue also called as i/o working queue.
• This queue keeps all the processes in waiting state due to availability of
I/O request.

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 −
Types of schedulers:
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler

9
1. Long-Term Scheduler:
1. It is also called a job scheduler.
2. The processes that are created are in the NEW state.
3. The programs are admitted to the memory for execution.
4. So before execution, the processes are put in the READY queue.
5. So, do they get into the ready queue themselves? Here comes the role of long-
term schedulers (LTS).
6. These schedulers select processes from job queue and put them into the ready
queue.
7. The main aim of long-term schedulers (LTS) is to maintain the degree of
multiprogramming.
8. Multiprogramming means executing multiple programs by a single
processor. It means if one process is not executing for some reason, then another
process will get a chance to get executed.

2. Short-Term Scheduler:
1. It is also called a CPU scheduler.
2. When the processes are in the ready queue, they are prepared to get
3. executed.
4. So the short-term schedulers select one process from the ready queue, put it in
the running queue, and allocate a processor(CPU) to it.
5. They are also known as the dispatcher who decides which process will execute
next.
6. They are faster than long-term schedulers.
7. The performance of the system depends on the choice of Short-term
schedulers.
8. If it selects the processes having high burst time, then, in that case, other
processes in the waiting queue will keep on waiting in the ready queue.
9. This situation is called starvation.

3. Medium-Term Scheduler
1. When the process is assigned CPU and the program execution starts,
program execution is sometimes suspended.
2. The reason could be an I/O request or some high-priority process.
3. In this case, suspended processes cannot make any progress towards
completion.
4. So the process has to be removed from the memory and make space for

10
other processes.
5. The suspended process is moved back to the secondary storage.
6. For example-Suppose, process 1 was executing, but it got suspended for
some reason, so process 1 is swapped out, and process 2 is swapped in.
This means swapping is taking place here. For doing swapping, we have a
medium-term scheduler.

Scheduling Criteria:
1. CPU scheduler determines the order and priority in which process are executed and
allocates the CPU time accordingly based on various criteria such as CPU utilization,
throughput, turn around time(T.A.T), waiting time(WT), response time.
2. I.e so which process will own the CPU for execution will keeping the other one on hold.
3. So, whenever the CPU looks idle os must select any of the process that are there in the
ready queue. This selection is acrried out by cpu scheduler.
4. The main goal of CPU scheduling is to maximize CPU utilization, minimize response
time, & ensure fair allocation of resources among different processes.
5. It is the main important component of modern operating system which Allow multiple
process to run simultaneously on a single processor.

11
1. 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.)
2. Arrival Time
The time at which the process enters into the ready queue is called the arrival
time.
3. Burst Time
The total amount of time required by the CPU to execute the whole process is
called the Burst Time.
4. Completion Time
The Time at which the process enters into the completion state or the time at
which the process completes its execution, is called completion time.
5. Turnaround time:
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.
or
The total amount of time spent by the process from its arrival to its completion
is called Turnaround time.

12
6. Waiting Time:
The Total amount of time for which the process waits for the CPU to be assigned is
called waiting time.
7. Response Time
• The difference between the arrival time and the time at which the process first gets
the CPU is called Response Time.
• Or
• 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 optimization.

Scheduling Algorithms:
CPU scheduling is a fundamental part of an operating system’s process management. It
involves determining the order in which processes are assigned to the CPU for execution,
maximizing CPU utilization and ensuring system efficiency. Since only one process can be
executed at a time on a CPU (in a single-core system), scheduling algorithms decide which
process will get the CPU next. There are several CPU scheduling algorithms, each with
different strategies for allocating CPU time to processes. These algorithms vary based on the
criteria they prioritize,
1. First-come, first-served scheduling (fcfs)
2. Shortest job first scheduling algorithm (sjf)
3. Round robin scheduling algorithm (rr)
4. Priority scheduling algorithm
5. Shortest remaining time first scheduling algorithm (srtf)
6. Multilevel queue scheduling algorithm

1. First-come, first-served scheduling (fcfs):


FCFS (First-Come, First-Served) is the simplest CPU scheduling algorithm. It operates
on the principle of processing requests in the order in which they arrive. If a process arrives
first in the ready queue, it gets executed first. FCFS is a non-preemptive scheduling algorithm,
meaning that once a process starts executing, it runs to completion before the CPU switches to
another process, even if other processes arrive while it's running.
How FCFS Works:
1. Process Arrival: Processes are placed in the ready queue in the order they arrive.
2. Execution: The first process in the queue gets the CPU and is allowed to execute
until completion.
3. Next Process: Once the current process finishes, the next process in the queue is
selected for execution, and so on.

13
4. No Preemption: Processes are not interrupted; each process runs until it terminates or
completes its time slice (in the case of a time-sharing system).
Example of FCFS Scheduling
Consider the following processes with their burst times (the amount of CPU time they require):

The processes arrive in the order of P1, P2, P3, and P4. Since FCFS schedules processes based on arrival
time, the order of execution will be:

1. P1: Starts at time 0, runs for 4 units, and finishes at time 4.

2. P2: Starts at time 4 (after P1 finishes), runs for 3 units, and finishes at time 7.

3. P3: Starts at time 7, runs for 1 unit, and finishes at time 8.

4. P4: Starts at time 8, runs for 2 units, and finishes at time 10.

Advantages of FCFS Scheduling:

• Simplicity: The FCFS algorithm is easy to implement and understand.

• Fair: It processes jobs in the order they arrive, giving each job a chance to run.

Disadvantages of FCFS Scheduling:

14
: • Convoy Effect: If a long process arrives first, all subsequent processes must wait, causing a
significant delay for shorter processes.

Advantages of FCFS Scheduling:

• Simplicity: The FCFS algorithm is easy to implement and understand.

• Fair: It processes jobs in the order they arrive, giving each job a chance to run

Disadvantages of FCFS Scheduling

• Convoy Effect: If a long process arrives first, all subsequent processes must wait, causing a significant
delay for shorter processes.

[Link] job first scheduling algorithm (sjf):


Shortest Job First (SJF) is a CPU scheduling algorithm that selects the process with the
shortest burst time (execution time) to execute next. The idea behind SJF is to reduce the
average waiting time and turnaround time by executing the shortest processes first, which
minimizes delays for shorter tasks.
There are two types of SJF scheduling:
1. Non-Preemptive SJF: Once a process starts executing, it runs to completion.
2. Preemptive SJF (Shortest Remaining Time First - SRTF): If a new process arrives
with a shorter burst time than the currently running process, it preempts the current process and
runs the shorter one.
How SJF Works (Non-Preemptive)
1. Process Arrival: Processes arrive and are placed in the ready queue.

15
2. Burst Time: The algorithm selects the process with the shortest burst time in the ready queue
and executes it.
3. Completion: After the selected process completes, the next shortest process in the queue is
selected, and the process continues

In Non-Preemptive SJF, the order of execution is determined by the shortest burst time in the
ready queue
• At time 0, the only process in the queue is P1, so it starts executing.
• At time 1, P2 arrives with a burst time of 4, but P1 is already running and will continue
• At time 2, P3 arrives with a burst time of 2, which is shorter than P1 and P2, but since SJF
is non-preemptive, P1 continues executing until it finishes at time 8.
At time 3, P4 arrives with a burst time of 1, which is the shortest, so P4 will be executed next.
• After P4 finishes at time 9, P3 runs, then P2 completes last.
The order of execution is: P1 → P4 → P3 → P2

Advantages of SJF Scheduling


1. Optimal for Minimum Average Waiting Time: SJF minimizes the total waiting time and
average waiting time for processes, leading to better CPU utilization.
Disadvantages of SJF Scheduling
1. Starvation: If short processes continue to arrive, long processes may never get a chance to
execute, leading to starvation for those processes.

16
[Link] scheduling algorithm:
Priority Scheduling is a CPU scheduling algorithm where each process is assigned a
priority value. The process with the highest priority is given the CPU first. Priority can be
assigned either externally (by the user or system) or internally (based on process characteristics
such as memory requirements, CPU burst time, etc.).
In priority scheduling, the process with the highest priority (usually the smallest
numerical value for numerical priority values) is selected for execution first. If multiple
processes have the same priority, a secondary scheduling algorithm (like FCFS or Round
Robin) is used to decide which one to execute.
Types of Priority Scheduling
1. Non-Preemptive Priority Scheduling:
Once a process starts executing, it runs to completion, and no other process can interrupt
it, even if a new process with a higher priority arrives.
[Link] Priority Scheduling:
If a new process with a higher priority arrives while a process is running, the currently
running process is preempted, and the higher-priority process is given the CPU.
How Priority Scheduling Works
1. Process Arrival: Processes arrive and are placed in the ready queue.
2. Priority Assignment: Each process is assigned a priority value.
3. Execution: The process with the highest priority is selected for execution. o If multiple
processes have the same priority, another scheduling algorithm (like FCFS) is used to decide
which process will execute first.
4. Preemption (in Preemptive version): If a higher-priority process arrives, it preempts the
current process, and the CPU is assigned to the new process.
Example of Priority Scheduling:
Consider the following processes, their arrival times, burst times, and priorities (lower
values represent higher priority):

17
AVERAGE OF TAT: 24/4= 6
AVERAGE OF WT: 14/4=3.5

[Link] robin scheduling algorithm (rr):


The Round Robin (RR) scheduling algorithm is one of the most widely used CPU
scheduling algorithms in time-sharing systems. It is a preemptive scheduling algorithm that
assigns a fixed time quantum (also known as a time slice) to each process in the ready queue.
The key idea is to allocate the CPU to each process for a fixed time period, and once the time
quantum expires, the process is moved to the back of the queue, and the next process gets the
CPU.
The Round Robin algorithm operates in a circular way, where each process is given a
chance to execute in a cyclic order.
How Round Robin Scheduling Works
1. Process Arrival: Processes arrive and are placed in the ready queue.
2. Time Quantum: A fixed time quantum (e.g., 2/3ms) is defined for the system
3. Execution: o The CPU scheduler selects the process at the front of the ready queue and
assigns it the CPU.
4. Process Completion or Preemption: o If the process does not finish in the given quantum, it
is preempted, again it go back into a ready queue, and the next process in the queue gets the
CPU.
5. Repeat: This continues until all processes have completed execution.
Round Robin Scheduling Example
Let’s consider the following processes with their burst times and arrival times:

18
Advantages of Round Robin Scheduling
1. Fairness: Each process is given an equal share of CPU time (the same time
quantum).
Disadvantages of Round Robin Scheduling
1. Average Waiting Time: Round Robin may lead to high average waiting time, especially if
the time quantum is too large or too small.
• If the time quantum is too large, the algorithm may act similarly to First-Come, First-
Served (FCFS).
• If the time quantum is too small, the overhead of context switching increases, reducing
overall efficiency.

[Link] REMAINING TIME FIRST (SRTF) SCHEDULING ALGORITHM:


Shortest Remaining Time First (SRTF) is a preemptive version of the Shortest Job
First (SJF) scheduling algorithm. It is also known as Preemptive SJF because it selects the
process with the shortest remaining burst time for execution.
The idea behind SRTF is that at any given time, the process with the shortest
remaining burst time will get the CPU.

19
If a new process arrives with a shorter remaining burst time than the currently running
process, the current process is preempted, and the new process is given the CPU.
[Link] QUEUE SCHEDULING ALGORITHM:
Multilevel Queue Scheduling (MLQ) is a CPU scheduling algorithm that divides
processes into different queues based on their priority, characteristics, or types.
Each queue has its own scheduling algorithm, and processes are assigned to specific
queues based on certain criteria (like priority, type, or behavior).
This algorithm helps organize processes based on their needs, with the goal of
providing efficient scheduling and managing processes that have different characteristics

20

You might also like