Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

PROCESS STATES

States of a Process in Operating Systems


A process has several stages that it passes through from beginning to
end. There must be a minimum of five states. Even though during
execution, the process could be in one of these states, the names of the
states are not standardized. Each process goes through several stages
throughout its life cycle.

Process States in Operating System


The states of a process are as follows:

• New (Create): In this step, the process is about to be created but


not yet created. It is the program that is present in secondary
memory that will be picked up by OS to create the process.
• Ready: New -> Ready to run. After the creation of a process, the
process enters the ready state i.e. the process is loaded into the
main memory. The process here is ready to run and is waiting to
get the CPU time for its execution. Processes that are ready for
execution by the CPU are maintained in a queue called ready
queue for ready processes.
• Run: The process is chosen from the ready queue by the CPU for
execution and the instructions within the process are executed by
any one of the available CPU cores.
• Blocked or Wait: Whenever the process requests access to I/O or
needs input from the user or needs access to a critical region(the
lock for which is already acquired) it enters the blocked or waits
state. The process continues to wait in the main memory and does
not require CPU. Once the I/O operation is completed the process
goes to the ready state.
• Terminated or Completed: Process is killed as well asPCBis
deleted. The resources allocated to the process will be released or
deallocated.
• Suspend Ready: Process that was initially in the ready state but
was swapped out of main memory(refer to Virtual Memory topic)
and placed onto external storage by the scheduler is said to be in
suspend ready state. The process will transition back to a ready
state whenever the process is again brought onto the main
memory.
• Suspend wait or suspend blocked: Similar to suspend ready but
uses the process which was performing I/O operation and lack of
main memory caused them to move to secondary memory. When
work is finished it may go to suspend ready.

How does a process move between different states in an operating


system?

A process can move between different states in an operating system based


on its execution status and resource availability. Here are some examples of
how a process can move between different states:
• New to ready: When a process is created, it is in a new state. It
moves to the ready state when the operating system has allocated
resources to it and it is ready to be executed.
• Ready to running: When the CPU becomes available, the
operating system selects a process from the ready queue
depending on various scheduling algorithms and moves it to the
running state.
• Running to blocked: When a process needs to wait for an event to
occur (I/O operation or system call), it moves to the blocked state.
For example, if a process needs to wait for user input, it moves to
the blocked state until the user provides the input.
• Running to ready: When a running process is preempted by the
operating system, it moves to the ready state. For example, if a
higher-priority process becomes ready, the operating system may
preempt the running process and move it to the ready state.
• Blocked to ready: When the event a blocked process was waiting
for occurs, the process moves to the ready state. For example, if a
process was waiting for user input and the input is provided, it
moves to the ready state.
• Running to terminated: When a process completes its execution
or is terminated by the operating system, it moves to the
terminated state.

Process Control Block (PCB) in Operating


Systems

A process in an operating system is a running instance of the software. It is


a fundamental concept in operating systems that represents a unit of work
or a task that the CPU may schedule and execute.

o Program vs. Process: A program is a collection of instructions that are


stored in secondary storage (for example, a hard disc), whereas a
process is the execution of those instructions in main memory. When
a program is put into memory and starts running, it is considered a
process.

o Process states: A process may be in several phases at any one time,


such as "new," "ready," "running," "waiting," and "terminated." These
phases show the development of the process and its communication
with the operating system.
o Process Control Block: As previously stated, each process is coupled
with a Process Control Block (PCB). The PCB holds critical process
information such as the process's state, program counter, CPU
registers, memory management details, I/O status, and more.

o Process creation: Processes are created by the operating system.


When a user launches a program, the operating system allocates the
necessary resources, generates a new PCB, and establishes the initial
process state. The parent process that creates the newly formed
process is referred to as the "parent process," and the newly formed
process is referred to as the "child process."

o Context Switching: Through context switching, the operating system


moves the CPU from one process to another. The current process's
state (including its program counter and CPU registers) is saved on
the PCB during a context transition, and the state of the next process
to be executed is loaded from the PCB. Consequently, many pieces of
software may effectively share the CPU.

o Process Scheduling: The process scheduler in the operating system


determines which processes get access to the CPU and for how long.
Scheduling techniques such as round-robin, priority-based, or shortest
job first assure equitable CPU time distribution and improve system
performance.

o Inter-process Communication(IPC): Processes may need to


communicate with one another and share data. Pipes, shared
memory, and message forwarding are examples of IPC methods that
aid in process communication and synchronization.

Processes are essential in multitasking because they allow the operating


system to manage and perform several activities at the same time. By
dividing program execution into several processes, the operating system
ensures system stability, resource utilization, and responsiveness to user
requests.

In some operating systems, a Process Control Block (PCB), sometimes known


as a Task Control Block (TCB), is a data structure that stores and maintains
critical process information. It serves as a central repository for information
relevant to a specific process, allowing the operating system to manage
and control process execution more effectively.

The Process Control Block is a collection of process-related data and


information. While the specifics vary based on the operating system, a
typical PCB has the following components

1. Process ID(PID): A distinct Process ID (PID) on the PCB serves as the


process's identifier within the operating system. The operating
system uses this ID to keep track of, manage, and differentiate
among processes.

2. Process State: The state of the process, such as running, waiting,


ready, or terminated, is indicated. The operating system makes use
of this data to schedule and manage operations.

3. Program Counter(PC): The program counter value, which indicates the


address of the following instruction to be performed in the process,
is stored on the PCB. The program counter is saved in the PCB of the
running process during context switches and then restored to let
execution continue where it left off.

4. CPU registers: Looks at how the process's associated CPU registers are
now working. Examples include stack pointers, general-purpose
registers, and program status flags. Processes can continue operating
uninterrupted during context changes by saving and restoring
register values.

5. Memory Management Information: Includes the process's memory


allocation information, such as the base and limit registers or page
tables. This information allows the operating system to manage the
process's memory requirements appropriately.

6. Priority:Some operating systems provide a priority value to each


process to decide the order in which processes receive CPU time. The
PCB may have a priority field that determines the process's priority
level, allowing the scheduler to distribute CPU resources
appropriately.
7. Parent Process ID(PPID):The PID of the parent process that gave rise
to the present process. This data is important for process
management and tracking process linkages, particularly in scenarios
requiring process hierarchy or process tree architectures.

8. I/O status: The PCB maintains information about I/O devices and data
related to the process. Open file descriptors, I/O buffers, and pending
I/O requests are all included. Storing this information enables the
operating system to manage I/O operations and efficiently handle
input/output requests.

9. Accounting information: Keeps track of the process's resource


utilization data, such as CPU time, memory usage, and I/O activities.
This data aids in performance evaluation and resource allocation
choices.

10. Inter-Process Communication (IPC) information: If a process


communicates with other processes, the PCB may contain fields or
pointers to communication channels, message queues, shared
memory regions, or synchronization primitives. This allows processes
to communicate and share data successfully.
11.Process Control Block

Process ID (PID)

Process State

Program Counter(PC)

CPU Registers

Memory Management Information

Priority

Parent Process ID (PID)

I/O Status Information

Accounting Information

Inter-process Communication Information


(IPC)

The Process Control Block is a fundamental data structure for the process
management capability of the operating system. It enables the operating
system to switch between processes, allocate resources, manage
interruptions, and maintain the general stability and performance of the
system. The PCB allows the operating system to retain control over process
execution and guarantee optimal resource utilization inside the system by
storing and maintaining critical process-related information.

You might also like