Process in Operating System (OS)

Learn via video courses

Overview

A process is defined as a sequence of instructions executed in a predefined order. In simple words, any program that is executed is termed as a process. Processes change their state as they execute and can be either new, ready, running, waiting or terminated. A process in OS is managed by the Process Control Block (PCB).

What is a Process in an Operating System?

In an operating system, a process is an instance of a program in execution. It is a basic unit of work that can be scheduled and executed by the operating system.

Components of a Process in OS

The components of a process are:

  • Program code/Text: The instructions that the process will execute.
  • Data: The data that the process will use during its execution.
  • Stack: A data structure that is used to store temporary data, such as function parameters and return addresses.
  • Heap: A data structure that is used to store dynamically allocated memory.
  • Process control block (PCB): A data structure that contains information about the process, such as its state, priority, and memory usage.

Process in the Memory

Process Life Cycle

The process life cycle is the sequence of states that a process goes through during its existence. The process life cycle can be divided into the following stages:

  1. New: The process has been created but has not yet been scheduled for execution.
  2. Ready: The process is ready to be executed.
  3. Running: The process is currently being executed.
  4. Waiting: The process is waiting for an event to occur, such as the completion of an I/O operation.
  5. Terminated: The process has finished executing.

Processes state

In the new state, the process has been created but has not yet been allocated any resources. The process is moved to the runnable state when it is scheduled for execution. The process is moved to the running state when it is given the CPU. The process is moved to the blocked state when it is waiting for an event to occur. The process is moved to the terminated state when it has finished executing.

Process Control Block

Process Control Block

An OS serves in the creation, scheduling and termination of processes. The OS consists of Process Control Block (PCB) that helps control the functioning of processes. Every process in OS has a PCB associated with it. A PCB keeps track of processes by storing information about various things like their state, I/O status and CPU Scheduling.

Understanding the components of a PCB will help us get to know the process information better. A PCB comprises of the following:

  1. Process ID: An identifier that helps us in identifying and locating a process.

  2. Process state: It identifies the state that the process is currently in. It could be a new process, ready, running, waiting or terminated.

  3. Program counter: It holds the address of the next instruction to be executed for the process. It also stores a count of the number of instructions in the process.

  4. CPU registers: The content of processor registers gets stored here when the process is in running state. The different kinds of CPU registers are accumulators, index and general-purpose registers, instruction register and condition code register.

  5. CPU scheduling information: A process needs to be scheduled for execution. Based on this scheduling, it goes from ready to running. CPU Scheduling information contains process priority (to determine which process goes first), pointers for scheduling queues (to mark the order of execution), and various other scheduling parameters.

  6. Accounting and business information: Contains details like CPU utilization, real-time used by the process, number of jobs or processes, etc.

  7. Memory-management information: Contains value of base and limit registers, details about page and segment tables. It depends on the memory system of the OS in use.

  8. I/O status information: Comprises I/O related information including list of I/O devices allocated to the process, status, etc.

Process States

The following are the process states in an operating system:

  1. New: When a program is started, the operating system creates a new process for it. The process is then placed in the new state. In the new state, the process has been created but has not yet been allocated any resources.
  2. Runnable: When a process is in the runnable state, it is ready to be executed. The operating system maintains a queue of runnable processes. The scheduler selects a process from the queue and moves it to the running state.
  3. Running: When a process is in the running state, it is currently being executed. The process has been given the CPU and is executing its instructions.
  4. Blocked: When a process is in the blocked state, it is waiting for an event to occur. The event could be the completion of an I/O operation, the arrival of a signal, or the availability of a resource. When the event occurs, the process is moved to the runnable state.
  5. Terminated: When a process has finished executing, it is moved to the terminated state. The operating system then releases all of the resources that were allocated to the process.

Difference between Process and the Program

FeatureProcessProgram
DefinitionAn instance of a program in execution.A set of instructions that can be executed by a computer.
ExistenceDynamic entity that exists for a limited time.Static entity that exists until it is deleted.
CreationCreated when a program is executed.Created when a program is written or compiled.
ResourcesRequires resources such as CPU time, memory, and I/O devices.Does not require any resources.
StateCan be in one of several states, such as new, runnable, running, blocked, or terminated.Always in the same state.
Control blockHas a process control block (PCB) that contains information about the process.Does not have a control block.
ExecutionCan be executed concurrently with other processes.Can only be executed one at a time.
ExampleA web browser, a word processor, a game.A source code file, an executable file.

Process Scheduling

Process scheduling is the act of deciding which process should be allocated the CPU for execution. The scheduler selects a process from the ready queue and moves it to the running state. The scheduler then gives the CPU to the running process.

The scheduler must consider a number of factors when making a scheduling decision. These factors include:

  • Priority: The priority of a process is a value that determines the order in which processes are scheduled for execution. Processes with higher priorities are scheduled for execution before processes with lower priorities.
  • CPU burst time: The CPU burst time of a process is the amount of time that the process needs to execute before it is blocked.
  • I/O burst time: The I/O burst time of a process is the amount of time that the process spends waiting for I/O operations to complete.
  • Arrival time: The arrival time of a process is the time at which the process is created.

The following are some of the most common process scheduling algorithms:

  • First-come, first-served (FCFS): In FCFS, processes are scheduled in the order in which they arrive.
  • Shortest job first (SJF): In SJF, the process with the shortest CPU burst time is scheduled next.
  • Priority scheduling: In priority scheduling, processes are scheduled according to their priority.
  • Round-robin (RR): In RR, each process is given a time slice. The processes are then scheduled in a round-robin fashion, with each process being given a time slice in turn.

Conclusion

  • Processes are the fundamental entities in OS that provide a way to manage the execution of multiple programs in a fair and efficient manner.
  • They offer concurrency, isolation, security, and flexibility.
  • Process management involves a variety of responsibilities such as process creation, scheduling, process termination, and deadlock.
  • The important elements of Process architecture are stack, heap, data and text.
  • The PCB (Process Control Block) is a data structure that is maintained by the Operating System for every process.
  • Processes have a well-defined life cycle with different states and are managed by the OS scheduler.
  • By understanding processes, we gain a better understanding of how OS manage programs.

See Also

Operations on Process in OS