FILE3 PROCESS
FILE3 PROCESS
Chapter 2
PROCESS
A process in an operating system (OS) is a program in execution. It is an active entity
that consists of code, data, and resources required to complete a task.
Components of the process
a) Object program: Code to be executed.
b) Data: It is used for executing the program.
c) Resources: While executing the program, it may require some resources.
d) Status of the process execution: It is used for verifying the status of the process
execution.
Processes and Programs
Process is a dynamic entity that is a program in execution. A process is a sequence of
information executions. Process exists in a limited span of time.
Two or more processes could be executing the same program, each using their
own data and resources.
Program is a static entity made up of program statement. Program contains the
instructions. A program exists at single place in space and continues to exist. A
program does not perform the action by itself.
PROCESS STATE DIAGRAM
The Two-State Model
The simplest way to think about a process’s lifecycle is with just two states:
1. Running: This means the process is actively using the CPU to do its work.
2. Not Running: This means the process is not currently using the CPU. It could
be waiting for something, like user input or data, or it might just be paused.
OPERATING SYSTEM -SEP
When a new process is created, it starts in the not running state. Initially, this process is
kept in a program called the dispatcher.
Here’s what happens step by step:
1. Not Running State: When the process is first created, it is not using the CPU.
2. Dispatcher Role: The dispatcher checks if the CPU is free (available for use).
3. Moving to Running State: If the CPU is free, the dispatcher lets the process use
the CPU, and it moves into the running state.
4. CPU Scheduler Role: When the CPU is available, the CPU scheduler decides
which process gets to run next. It picks the process based on a set of rules called
the scheduling scheme, which varies from one operating system to another.
The five states that are being used in this process model are:
Running: It means a process that is currently being executed. Assuming that there is
only a single processor in the below execution process, so there will be at most one
processor at a time that can be running in the state.
Ready: It means a process that is prepared to execute when given the opportunity by
the OS.
Blocked/Waiting: It means that a process cannot continue executing until some event
occurs like for example, the completion of an input-output operation.
New: It means a new process that has been created but has not yet been admitted by
the OS for its execution. A new process is not loaded into the main memory, but its
process control block (PCB) has been created.
Exit/Terminate: A process or job that has been released by the OS, either because it is
completed or is aborted for some issue.
OPERATING SYSTEM -SEP
With the creation of a process, a PCB is created which controls how that process is
being carried out. The PCB is created with the aim of helping the OS to manage the
enormous amounts of tasks that are being carried out in the system. PCB is helpful in
doing that as it helps the OS to actively monitor the process and redirect system
resources to each process accordingly. The OS creates a PCB for every process which
is created, and it contains all the important information about the process. All this
information is afterward used by the OS to manage processes and run them efficiently.
Primary Terminologies Related to Process Control Block
Process State: The state of the process is stored in the PCB which helps to manage the
processes and schedule them. There are different states for a process which are
“running,” “waiting,” “ready,” or “terminated.”
Process ID: The OS assigns a unique identifier to every process as soon as it is created
which is known as Process ID, this helps to distinguish between processes.
Program Counter: While running processes when the context switch occurs the last
instruction to be executed is stored in the program counter which helps in resuming the
execution of the process from where it left off.
OPERATING SYSTEM -SEP
CPU Registers: The CPU registers of the process helps to restore the state of the
process so the PCB stores a copy of them.
Memory Information: The information like the base address or total memory
allocated to a process is stored in PCB which helps in efficient memory allocation to
the processes.
Process Scheduling Information: The priority of the processes or the algorithm of
scheduling is stored in the PCB to help in making scheduling decisions of the OS.
Accounting Information: The information such as CPU time, memory usage, etc
helps the OS to monitor the performance of the process.
PROCESS SCHEDULING
A process is the instance of a computer program in execution.
• Scheduling is important in operating systems with multiprogramming as
multiple processes might be eligible for running at a time.
• One of the key responsibilities of an Operating System (OS) is to decide which
programs will execute on the CPU.
• Process Schedulers are fundamental components of operating systems
responsible for deciding the order in which processes are executed by the CPU.
In simpler terms, they manage how the CPU allocates its time among multiple
tasks or processes that are competing for its attention.
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. Throughout its lifetime, a process moves between
various scheduling queues, such as the ready queue, waiting queue, or devices queue.
OPERATING SYSTEM -SEP
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.
• 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.
Scheduling Queues
The Operating system manages various types of queues for each of the process states.
The PCB related to the process is also stored in the queue of the same state. If the
Process is moved from one state to another state then its PCB is also unlinked from the
corresponding queue and added to the other state queue in which the transition is
made.
3. Waiting Queue
When the process needs some IO operation in order to complete its execution, OS
changes the state of the process from running to waiting. The context (PCB) associated
with the process gets stored on the waiting queue which will be used by the Processor
when the process finishes the IO.
Schedulers:
There are three types of process schedulers:
1. Long Term or Job Scheduler
Long Term Scheduler loads a process from disk to main memory for execution. The
new process to the ‘Ready State’.
• It mainly moves processes from Job Queue to Ready Queue.
• It controls the Degree of Multi-programming, i.e., the number of processes
present in a ready state or in main memory at any point in time.
• It is important that the long-term scheduler make a careful selection of both I/O
and CPU-bound processes. I/O-bound tasks are which use much of their time in
input and output operations while CPU-bound processes are which spend their
time on the CPU. The job scheduler increases efficiency by maintaining a
balance between the two.
• 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).
2. Short-Term or CPU Scheduler
CPU Scheduler is responsible for selecting one process from the ready state for
running (or assigning CPU to it).
• STS (Short Term Scheduler) must select a new process for the CPU frequently
to avoid starvation.
• The CPU scheduler uses different scheduling algorithms to balance the
allocation of CPU time.
• It picks a process from ready queue.
• Its main objective is to make the best use of CPU.
• It mainly calls dispatcher.
OPERATING SYSTEM -SEP
3. Medium-Term Scheduler
Medium Term Scheduler (MTS) is responsible for moving a process from memory to
disk (or swapping).
It reduces the degree of multiprogramming (Number of processes present in main
memory).
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 (of CPU bound and IO bound)
When needed, it brings process back into memory and pick up right where it left off.
It is faster than long term and slower than short term.
OPERATING SYSTEM -SEP
Medium Term
Long Term Scheduler Short Term Schedular Scheduler
It is a process-swapping
It is a job scheduler It is a CPU scheduler
scheduler.
in an operating system. These processes interact with each other by sharing the
resources such as CPU, memory, and I/O devices to complete the task.
Advantages of Cooperating Process in Operating System
There are various advantages of cooperating process in the operating system. Some
advantages of the cooperating system are as follows:
1. Information Sharing
Cooperating processes can be used to share information between various
processes. It could involve having access to the same files. A technique is necessary
so that the processes may access the files concurrently.
2. Modularity
Modularity refers to the division of complex tasks into smaller subtasks. Different
cooperating processes can complete these smaller subtasks. As a result, the required
tasks are completed more quickly and efficiently.
3. Computation Speedup
Cooperating processes can be used to accomplish subtasks of a single task
simultaneously. It improves computation speed by allowing the task to be
accomplished faster. Although, it is only possible if the system contains several
processing elements.
4. Convenience
There are multiple tasks that a user requires to perform, such as printing, compiling,
editing, etc. It is more convenient if these activities may be managed through
cooperating processes.
Concurrent execution of cooperating processes needs systems that enable processes
to communicate and synchronize their actions.
Methods of Cooperating Process
Cooperating processes may coordinate with each other by sharing data or messages.
The methods are given below:
1. Cooperation by sharing
The processes may cooperate by sharing data, including variables, memory,
databases, etc. The critical section provides data integrity, and writing is mutually
exclusive to avoid inconsistent data.
OPERATING SYSTEM -SEP
Here, you see a diagram that shows cooperation by sharing. In this diagram,
Process P1 and P2 may cooperate by using shared data like files, databases,
variables, memory, etc.
2. Cooperation by Communication
The cooperating processes may cooperate by using messages. If every process
waits for a message from another process to execute a task, it may cause a
deadlock. If a process does not receive any messages, it may cause starvation.
Here, you have seen a diagram that shows cooperation by communication. In this
diagram, Process P1 and P2 may cooperate by using messages to communicate.
OPERATING SYSTEM -SEP
7. FIFO
Pipe:-
The pipe is a type of data channel that is unidirectional in nature. It means that the
data in this type of data channel can be moved in only a single direction at a time.
Still, one can use two-channel of this type, so that he can able to send and receive
data in two processes. Typically, it uses the standard methods for input and output.
These pipes are used in all types of POSIX systems and in different versions of
window operating systems as well.
Shared Memory:-
It can be referred to as a type of memory that can be used or accessed by multiple
processes simultaneously. It is primarily used so that the processes can
communicate with each other. Therefore the shared memory is used by almost all
POSIX and Windows operating systems as well.
Message Queue:-
In general, several different messages are allowed to read and write the data to the
message queue. In the message queue, the messages are stored or stay in the queue
unless their recipients retrieve them. In short, we can also say that the message
queue is very helpful in inter-process communication and used by all operating
systems.
To understand the concept of Message queue and Shared memory in more detail,
let's take a look at its diagram given below:
Message Passing:-
OPERATING SYSTEM -SEP