Open In App

Process in Operating System

Last Updated : 13 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A process is a program in execution. For example, when we write a program in C or C++ and compile it, the compiler creates binary code. The original code and binary code are both programs. When we actually run the binary code, it becomes a process.

  • A process is an 'active' entity instead of a program, which is considered a 'passive' entity.
  • A single program can create many processes when run multiple times; for example, when we open a .exe or binary file multiple times, multiple instances begin (multiple processes are created). .

How Does a Process Look Like in Memory? 

A process in memory is divided into several distinct sections, each serving a different purpose. Here's how a process typically looks in memory.

Process_look
Process structure
  • Text Section: A text or code segment contains executable instructions. It is typically a read only section
  • Stack: The stack contains temporary data, such as function parameters, returns addresses, and local variables. 
  • Data Section: Contains the global variable. 
  • Heap Section: Dynamically memory allocated to process during its run time.

Attributes of a Process

A process has several important attributes that help the operating system manage and control it. These attributes are stored in a structure called the Process Control Block (PCB) (sometimes called a task control block). The PCB keeps all the key information about the process, including:

  1. Process ID (PID): A unique number assigned to each process so the operating system can identify it.
  2. Process State: This shows the current status of the process, like whether it is running, waiting, or ready to execute.
  3. Priority and other CPU Scheduling Information: Data that helps the operating system decide which process should run next, like priority levels and pointers to scheduling queues.
  4. I/O Information: Information about input/output devices the process is using.
  5. File Descriptors: Information about open files files and network connections.
  6. Accounting Information: Tracks how long the process has run, the amount of CPU time used, and other resource usage data.
  7. Memory Management Information: Details about the memory space allocated to the process, including where it is loaded in memory and the structure of its memory layout (stack, heap, etc.).

These attributes in the PCB help the operating system control, schedule, and manage each process effectively.

States of Process

A process is in one of the following process states

process-states

  • New: Newly Created Process (or) being-created process.
  • Ready: After the creation process moves to the Ready state, i.e. the process is ready for execution.
  • Running: Currently running process in CPU (only one process at a time can be under execution in a single processor).
  • Wait (or Block): When a process requests I/O access.
  • Complete (or Terminated): The process completed its execution.
  • Suspended Ready: When the ready queue becomes full, some processes are moved to a suspended ready state
  • Suspended Block: When the waiting queue becomes full.

Process Creation

unix_process_creation-660
Process Creation

1. Parent Process Calls Create Function

  • A parent process calls a system call to create a new process.

In Unix/Linux: fork()
In Windows: CreateProcess()

  • This is typically done when a user starts a program or a process spawns a child.

2. Allocate Memory and Resources

  • The OS allocates memory for the new process in both the code and data segments.
  • It also allocates other required resources such as: File descriptors, I/O buffers & Stack and heap space.

3. Create a Unique Process Control Block (PCB)

  • The OS creates a Process Control Block for the new process.
  • The PCB contains:

Process ID (PID)
Process state (Ready, Running, etc.)
Program counter (PC)
CPU registers
Scheduling information
Memory management info, etc.

4. Initialize the Process Context

  • The new process inherits or initializes: Register values, Program counter (PC) set to start of program, Stack pointer initialized & File table copied (if needed).
  • In some systems (fork()), the child gets a copy of the parent's context.
  • The OS links the new process into:

Job queue
Ready queue
Parent-child hierarchy

6. Set Process State to READY

  • The new process is marked as READY and placed in the ready queue.
  • It will wait for the CPU scheduler to dispatch it.

7. Scheduler Picks the Process to Run

  • The CPU scheduler eventually selects the new process from the ready queue.
  • It dispatches the process to the CPU, changing its state to RUNNING.

Example: In UNIX/Linux

int pid = fork();
if (pid == 0) {
// Child Process
execvp("program", args);
}
else {
// Parent Process
wait(NULL);
}

Here:

  • fork() creates a duplicate process.
  • execvp() replaces the child’s memory with a new program.

Process Deletion 

Processes terminate themselves when they finish executing their last statement, after which the operating system uses the exit() system call to delete their context. Then all the resources held by that process like physical and virtual memory, 10 buffers, open files, etc., are taken back by the operating system. A process P can be terminated either by the operating system or by the parent process of P. A parent may terminate a process due to one of the following reasons:

  • When task given to the child is not required now.
  • When the child has taken more resources than its limit.
  • The parent of the process is exiting, as a result, all its children are deleted. This is called cascaded termination.

A process can be terminated/deleted in many ways. Some of the ways are:

  • Normal termination: The process completes its task and calls an exit() system call. The operating system cleans up the resources used by the process and removes it from the process table.
  • Abnormal termination/Error exit: A process may terminate abnormally if it encounters an error or needs to stop immediately. This can happen through the abort() system call.
  • Termination by parent process: A parent process may terminate a child process when the child finishes its task. This is done by the using kill() system call.
  • Termination by signal: The parent process can also send specific signals like SIGSTOP to pause the child or SIGKILL to immediately terminate it.

Similar Reads