Process in Operating System

Process definition, Process States in OS, Process State Diagram, and Process vs Program discussed in detail.


Process in operating system

Any program you run on your computer is the process at the time of execution.

Many processes have been running in the background when you are working on your computer. To understand how the process works in an operating system? Be with us in this article.

What is Process in OS?

A process is a program at the time of execution. The process is more than the program code. It includes the program counter, the process stack, the content of the process register, etc.

The purpose of the process stack is to store temporary data, such as subroutine parameters, return addresses, and temporary variables.

Process States in OS

  • New: When a process is created.
  • Running: When the process is executing.
  • Waiting: When the process is waiting for some event to occur.
  • Ready: When the process is waiting for assigned to a processor.
  • Terminate: When the process has finished execution.

Many processes can be run in any processor at any time. However, many processes may be in the ready queue waiting for states. Consider the figure above depicts the state diagram of the process states.

Process states in OS
Process State Diagram

New to Ready

The operating system creates a process. And, prepares the process to be executed, and then the operating system moves the process into the ready queue.

Ready to Running

When selecting a process to run, the operating system selects one of the jobs for the ready queue and moves the process from the ready state to the running state.

Running to Terminated

When the execution of a process has been completed, then the operating system terminates that process from its running state.

Sometimes the operating system terminates the process for some other reasons. It includes time limit exceeded, memory unavailable access violation, protection error, I/O failure, data misuse, and so on.

Running to Ready

When the time slot for the processor expires or if the processor receives an interrupt signal, then the operating system shifts the running process to the ready state.

For example, when process P1 is being executed by the processor, at the same time, process P2 generates an interrupt signal to the processor. Then the processor compares the priorities of processes P1 and P2. If P1>P2, then the processor continues executing P1. Otherwise, the processor switches to process P2, and process P1 is moved to the ready state.

Running to Waiting

A process is put into the waiting state if the process needs an event to occur or an I/O device is to read. The operating system does not provide the I/O or event immediately, so the process is moved to the waiting state by the operating system.

Waiting to Ready

A process in the blocked state is moved to the ready state when the event for which it has been waiting occurs.

For example, a process that is running needs an I/O device, so the process is moved to a wait or blocked state. Now the I/O device is provided by the operating system, so the process moved to the ready state from the waiting state.

Process creation in OS

When a user initiates to execute a program, the operating system creates a process to represent the execution of this program. The creation of executable programs includes many steps for this. Consider the figure below.

Process creation in OS
Process Creation Diagram

Process Termination

The process terminates from the running state and includes so many causes. Generally, the process termination occurs when its execution has finished.

There may be some other reasons for the process termination.

  • Time slot expired
  • Memory boundary violation
  • Input/Output failure
  • Parent termination
  • Parent request
  • Invalid instruction

What is a Process Control Block(PCB)?

The PCB(Process Control Block) is a central store of information that allows the operating system to locate all the key information about the process.

The operating system uses this information and performs the operations in the process. It includes suspending a process, resuming the process, changing the process priority, dispatching the process, naming the process, and so on.

Process Control Block in OS
Process Control Block in OS

Operations on Process

A system that manages a process must be able to perform certain operations with the process. These include a seven-state process model.

  • Create a process
  • Destroy a process
  • Resume a process(Restart the process)
  • Change the priority of a process
  • Block of process
  • Wake up a process
  • Enable process to communicate with other processes

Changing the priority of the process involves nothing more than modifying the priority value in the PCB. Here the meaning of operation resumes a process is to submit the process from a suspended state to a ready state.

Concurrent Process

Two processes are serial when the execution of one process is complete before the other starts. If the two processes are said to be concurrent, they are not serial, and their execution can overlap in time.

Here is an example of a concurrent process in an operating system. Let’s assume there are three processes P1, P2, and P3, and the execution time is T. According to the figure, the execution time of P1, P2, and P3 overlap, so these are called concurrent process models.

Concurrent process in OS
Concurrent Process in OS

Process vs Program

There are many differences between process and program. Some main points we have discussed are below.

  • A process consists of instruction execution in machine code, but a program consists of instruction in any programming language.
  • A process is a dynamic object, but a program is a static object.
  • Process resides in main memory, but program resides in secondary memory.
  • The period for the process is limited, but the period for the program is unlimited.
  • A process is an active entity, and a program is a passive entity.