0% found this document useful (0 votes)
24 views13 pages

Unit 2

The document discusses process management in operating systems, focusing on process scheduling, creation, termination, and state transitions. It outlines the roles of different types of schedulers (long-term, short-term, and medium-term) and various CPU scheduling algorithms such as FCFS, SJF, priority scheduling, and round robin. Additionally, it highlights the importance of CPU scheduling criteria like CPU utilization, throughput, waiting time, and turnaround time.

Uploaded by

legend.selva2715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views13 pages

Unit 2

The document discusses process management in operating systems, focusing on process scheduling, creation, termination, and state transitions. It outlines the roles of different types of schedulers (long-term, short-term, and medium-term) and various CPU scheduling algorithms such as FCFS, SJF, priority scheduling, and round robin. Additionally, it highlights the importance of CPU scheduling criteria like CPU utilization, throughput, waiting time, and turnaround time.

Uploaded by

legend.selva2715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Process Management

In multiprogramming environment, the OS decides which process gets the processor when
and for how much time. This function is called process scheduling.
An Operating System does the following activities for processor management −
 Keeps track of processor and status of process. The program responsible for this task is
known as traffic controller.
 Allocates the processor (CPU) to a process.
 De-allocates processor when a process is no longer required.
A process can be thought of as a program in execution. A process will need certain resources—
such as CPU time, memory, files, and I/O devices —to accomplish its task. These resources are
allocated to the process either when it is created or while it is executing.

The operating system is responsible for several important aspects of process and thread
management:
 The creation and deletion of both user and system processes
 The scheduling of processes
 The provision of mechanisms for synchronization, communication, and
deadlock handling for processes.

The Process
 A process is a program in execution.
 A process is more than the program code, which is sometimes known as the text section.
 It also includes the current activity, as represented by the value of the program counter
and the contents of the processor’s registers.
 A process generally also includes the process stack, which contains temporary data
(such as function parameters, return addresses, and local variables), and a data section,
which contains global variables.
 A program is a passive entity, such as a file containing a list of instructions stored on
disk (often called an executable file).
 In contrast, a process is an active entity, with a program counter specifying the
next instruction to execute and a set of associated resources
Process State
As a process executes, it changes state. The state of a process is defined in part by the
current activity of that process. A process may be in one of the following states:

• New. The process is being created.


• Running. Instructions are being executed.
• Waiting. The process is waiting for some event to occur (such as an I/O completion).
• Ready. The process is waiting to be assigned to a processor.
• Terminated. The process has finished execution.

Operation on a Process

The execution of a process is a complex activity. It involves various operations. Following are the
operations that are performed while execution of a process:

Process operations, such as creation, scheduling, and termination, are crucial for managing an
operating system’s performance.
1. Creation
This is the initial step of the process execution activity. Process creation means the construction of a
new process for execution. This might be performed by the system, the user, or the old process
itself. There are several events that lead to the process creation. Some of the such events are the
following:
When we start the computer, the system creates several background processes.
A user may request to create a new process.
A process can create a new process itself while executing.
The batch system takes initiation of a batch job.

2. Scheduling/Dispatching
The event or activity in which the state of the process is changed from ready to run. It means the
operating system puts the process from the ready state into the running state. Dispatching is done by
the operating system when the resources are free or the process has higher priority than the ongoing
process. There are various other cases in which the process in the running state is preempted and the
process in the ready state is dispatched by the operating system.

3. Blocking
When a process invokes an input-output system call that blocks the process, and operating system is
put in block mode. Block mode is basically a mode where the process waits for input-output. Hence
on the demand of the process itself, the operating system blocks the process and dispatches another
process to the processor. Hence, in process-blocking operations, the operating system puts the
process in a ‘waiting’ state.

4. Preemption
When a timeout occurs that means the process hadn’t been terminated in the allotted time interval
and the next process is ready to execute, then the operating system preempts the process. This
operation is only valid where CPU scheduling supports preemption. Basically, this happens in
priority scheduling where on the incoming of high priority process the ongoing process is
preempted. Hence, in process preemption operation, the operating system puts the process in a
‘ready’ state.

5. Process Termination
Process termination is the activity of ending the process. In other words, process termination is the
relaxation of computer resources taken by the process for the execution. Like creation, in
termination also there may be several events that may lead to the process of termination.
Some of them are:
The process completes its execution fully and it indicates to the OS that it has finished.
The operating system itself terminates the process due to service errors.
There may be a problem in hardware that terminates the process.

Process Control Block

Each process is represented in the operating system by a process control block (PCB)—also
called a task control block.
A PCB is shown below. It contains many pieces of information associated with a
specific process, including these:
 Process state. The state may be new, ready, running, waiting, halted, and so on.
 Program counter. The counter indicates the address of the next instruction to
be executed for this process.

SCHEDULERS:
 A process migrates between the various scheduling queues throughout its life-time
purposes.
 The OS must select for scheduling processes from these queues in some fashion.
 This selection process is carried out by the appropriate scheduler.
 In a batch system, more processes are submitted and then executed immediately.
 So these processes are spooled to a mass storage device like disk, where they are kept
for later execution.

Types of schedulers:
There are 3 types of schedulers mainly used:

1. Long term scheduler: Long term scheduler selects process from the disk & loads them into
memory for execution. It controls the degree of multi-programming i.e. no. of processes in
memory. It executes less frequently than other schedulers. If the degree of
multiprogramming is stable than the average rate of process creation is equal to the average
departure rate of processes leaving the system. So, the long term scheduler is needed to be
invoked only when a process leaves the system.
Due to longer intervals between executions it can afford to take more time to decide which
process should be selected for execution. Most processes in the CPU are either I/O bound
or CPU bound. An I/O bound process (an interactive ‘C’ program is one that spends most
of its time in I/O operation than it spends in doing I/O operation. A CPU bound process is
one that spends more of its time in doing computations than I/O operations (complex
sorting program). It is important that the long term scheduler should select a good mix of
I/O bound & CPU bound processes.

2. Short term scheduler: The short term scheduler selects among the process that are ready to
execute & allocates the CPU to one of them. The primary distinction between these two
schedulers is the frequency of their execution. The short-term scheduler must select a new
process for the CPU quite frequently. It must execute at least one in 100ms. Due to the short
duration of time between executions, it must be very fast.

3.Medium term scheduler: some operating systems introduce an additional intermediate level of
scheduling known as medium - term scheduler.
The main idea behind this scheduler is that sometimes it is advantageous to remove processes
from memory & thus reduce the degree of multiprogramming. At some later time, the process
can be reintroduced into memory & its execution can be continued from where it had left off.
This is called as swapping.
The process is swapped out & swapped in later by medium term scheduler.
Swapping is necessary to improve the process miss or due to some change in memory requirements,
the available memory limit is exceeded which requires some memory to be freed up.
• CPU registers. The registers vary in number and type, depending on the computer
architecture. They include accumulators, index registers, stack pointers, and
general-purpose registers, plus any condition-code information.
 CPU-scheduling information. This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
 Memory-management information. This information may include such items as the
value of the base and limit registers and the page tables, or the segment tables,
depending on the memory system used by the operating system.
 Accounting information. This information includes the amount of CPU and real
time used, time limits, account numbers, job or process numbers, and so on.
 I/O status information. This information includes the list of I/O devices allocated to
the process, a list of open files, and so on.
What is CPU Scheduling?

CPU Scheduling is a process of determining which process will own CPU for execution while
another process is on hold. The main task of CPU scheduling is to make sure that whenever the
CPU remains idle, the OS at least select one of the processes available in the ready queue for
execution. The selection process will be carried out by the CPU scheduler. It selects one of the
processes in memory that are ready for execution.

Preemptive Scheduling

In Preemptive Scheduling, the tasks are mostly assigned with their priorities. Sometimes it is
important to run a task with a higher priority before another lower priority task, even if the lower
priority task is still running. The lower priority task holds for some time and resumes when the
higher priority task finishes its execution.

Non-Preemptive Scheduling

In this type of scheduling method, the CPU has been allocated to a specific process. The process
that keeps the CPU busy will release the CPU either by switching context or terminating. It is the
only method that can be used for various hardware platforms. That's because it doesn't need
special hardware (for example, a timer) like preemptive scheduling.

When scheduling is Preemptive or Non-Preemptive?

To determine if scheduling is preemptive or non-preemptive, consider these four parameters:

1. A process switches from the running to the waiting state.


2. Specific process switches from the running state to the ready state.
3. Specific process switches from the waiting state to the ready state.
4. Process finished its execution and terminated.

Only conditions 1 and 4 apply, the scheduling is called non-

preemptive. All other scheduling are preemptive.

Important CPU scheduling Terminologies

 Burst Time/Execution Time: It is a time required by the process to complete execution.


It is also called running time.
 Arrival Time: when a process enters in a ready state
 Finish Time: when process complete and exit from a system
 Multiprogramming: A number of programs which can be present in memory at the
same time.
 Jobs: It is a type of program without any kind of user interaction.
 User: It is a kind of program having user interaction.
 Process: It is the reference that is used for both job and user.
 CPU/IO burst cycle: Characterizes process execution, which alternates between CPU
and I/O activity. CPU times are usually shorter than the time of I/O.

CPU Scheduling Criteria

A CPU scheduling algorithm tries to maximize and minimize the following:

Maximize:

CPU utilization: CPU utilization is the main task in which the operating system needs to make
sure that CPU remains as busy as possible. It can range from 0 to 100 percent. However, for the
RTOS, it can be range from 40 percent for low-level and 90 percent for the high-level system.

Throughput: The number of processes that finish their execution per unit time is known
Throughput. So, when the CPU is busy executing the process, at that time, work is being done,
and the work completed per unit time is called Throughput.

Minimize:

Waiting time: Waiting time is an amount that specific process needs to wait in the ready queue.

Response time: It is an amount to time in which the request was submitted until the first
response is produced.

Turnaround Time: Turnaround time is an amount of time to execute a specific process. It is the
calculation of the total time spent waiting to get into the memory, waiting in the queue and,
executing on the CPU. The period between the time of process submission to the completion
time is the turnaround time.
CPU Scheduling Algorithm:
CPU Scheduling deals with the problem of deciding which of the processes in the ready queue is
to
be allocated first to the CPU. There are four types of CPU scheduling that exist.

First Come, First Served Scheduling (FCFS) Algorithm:This is the simplest CPU scheduling
algorithm. In this scheme, the process which requests the CPU first, that is allocated to the CPU
first. The implementation of the FCFS algorithm is easily managed with a FIFO queue. When a
process enters the ready queue its PCB is linked onto the rear of the queue. The average waiting
time under FCFS policy is quiet long.

 Jobs are executed on first come, first serve basis.


 It is a non-preemptive, pre-emptive scheduling algorithm.
 Easy to understand and implement.
 Its implementation is based on FIFO queue.
 Poor in performance as average wait time is high.

The FCFS algorithm is non preemptive means once the CPU has been allocated to a process
then the process keeps the CPU until the release the CPU either by terminating or
requesting I/O.
2. Shortest Job First Scheduling (SJF) Algorithm: This algorithm associates with each
process if the CPU is available. This scheduling is also known as shortest next CPU burst,
because the scheduling is done by examining the length of the next CPU burst of the process
rather than its total length.

 This is also known as shortest job first, or SJF


 This is a non-preemptive, pre-emptive scheduling algorithm.
 Best approach to minimize waiting time.
 Easy to implement in Batch systems where required CPU time is known in advance.
 Impossible to implement in interactive systems where required CPU time is not known.
 The processer should know in advance how much time process will take.
The SJF algorithm may be either preemptive or non preemptive algorithm. The preemptive SJF
is also known as shortest remaining time first.

Priority Scheduling Algorithm: In this scheduling a priority is associated with each


process and the CPU is allocated to the process with the highest priority. Equal priority
processes are scheduled in FCFS manner. Consider the following example:

 Priority scheduling is a non-preemptive algorithm and one of the most common


scheduling algorithms in batch systems.
 Each process is assigned a priority. Process with highest priority is to be executed first
and so on.
 Processes with same priority are executed on first come first served basis.
 Priority can be decided based on memory requirements, time requirements or any other
resource requirement.
4. Round Robin Scheduling Algorithm: This type of algorithm is designed only for the time
sharing system. It is similar to FCFS scheduling with preemption condition to switch between
processes. A small unit of time called quantum time or time slice is used to switch between
the processes. The average waiting time under the round robin policy is quiet long.

 Round Robin is the preemptive process scheduling algorithm.


 Each process is provided a fix time to execute, it is called a quantum.
 Once a process is executed for a given time period, it is preempted and other process
executes for a given time period.
 Context switching is used to save states of preempted processes.

Multiple-Level Queues Scheduling

This algorithm separates the ready queue into various separate queues. In this method, processes
are assigned to a queue based on a specific property of the process, like the process priority, size
of the memory, etc.
However, this is not an independent scheduling OS algorithm as it needs to use other types of
algorithms in order to schedule the jobs.

Characteristic of Multiple-Level Queues Scheduling:

 Multiple queues should be maintained for processes with some characteristics.


 Every queue may have its separate scheduling algorithms.
 Priorities are given for each queue.

The Purpose of a Scheduling algorithm

Here are the reasons for using a scheduling algorithm:

 The CPU uses scheduling to improve its efficiency.


 It helps you to allocate resources among competing processes.
 The maximum utilization of CPU can be obtained with multi-programming.
 The processes which are to be executed are in ready queue.

You might also like