Tutorials Logic
Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Tools
Online Compiler JSON Formatter Regex Tester CSS Unit Converter Color Picker
Compiler Tools

Process Management in OS — PCB, States, Context Switch

What is Process Management?

Process management is the part of an operating system that creates, schedules, runs, pauses, resumes, and terminates processes. A computer usually has many programs open at the same time, but the CPU can execute only a limited number of tasks at once. The operating system makes this sharing possible.

The OS keeps track of every running process, gives it CPU time, allocates memory and I/O resources, handles communication between processes, and cleans up resources when the process finishes.

Program vs Process

A program and a process are related, but they are not the same. A program is passive code stored on disk. A process is an active instance of that program while it is running.

Feature Program Process
Meaning A set of instructions stored in a file A program currently in execution
Nature Passive Active
Storage Secondary storage such as HDD or SSD Main memory while running
Resources Does not own CPU, registers, or open files Has allocated resources such as memory, files, and CPU state
Example chrome.exe stored on disk Each opened Chrome instance or tab-related process

Process in Memory

When a program becomes a process, the OS loads it into memory and organizes its memory into different sections. Each section has a specific purpose.

  • Text section: Contains the executable program instructions.
  • Data section: Stores global and static variables.
  • Heap: Stores dynamically allocated memory during runtime.
  • Stack: Stores function calls, local variables, and return addresses.
  • Process Control Block: Stores OS-level information about the process.
Simple Process Memory Layout
High Memory
+------------------+
| Stack            |  Function calls and local variables
+------------------+
| Heap             |  Dynamic memory allocation
+------------------+
| Data             |  Global and static variables
+------------------+
| Text / Code      |  Program instructions
+------------------+
Low Memory

Process Control Block (PCB)

The Process Control Block, or PCB, is a kernel data structure that stores all important information about a process. The OS uses the PCB to pause a process, resume it later, schedule it, identify it, and manage its resources.

PCB Field Purpose
Process ID (PID) Unique number used to identify the process
Process state Current state such as ready, running, waiting, or terminated
Program counter Address of the next instruction to execute
CPU registers Saved register values needed to resume execution
CPU scheduling information Priority, scheduling queue pointers, and time-related details
Memory management information Page tables, segment tables, base registers, or limit registers
I/O status information Open files, allocated devices, and pending I/O requests
Accounting information CPU time used, user ID, process owner, and resource usage

Process States

A process moves through different states during its lifetime. These states help the OS decide which process should run, which process is waiting, and which process is finished.

  • New: The process is being created and its PCB is being initialized.
  • Ready: The process is in memory and waiting for CPU time.
  • Running: The process is currently executing on a CPU core.
  • Waiting or blocked: The process is waiting for I/O, a signal, or some event.
  • Terminated: The process has completed or has been killed.
Process State Transitions
New --admitted--> Ready --dispatch--> Running --exit--> Terminated
                         ^               |
                         |               |
                  I/O done               | I/O request
                         |               v
                      Waiting <--- blocked

Running --preempted--> Ready

Process Queues

The operating system organizes processes into queues. A queue is a waiting line of processes that need the same kind of service.

Queue Contains Purpose
Job queue All processes in the system Tracks processes that exist or are waiting to enter memory
Ready queue Processes ready to execute CPU scheduler chooses from this queue
Device queue Processes waiting for an I/O device Each device can have its own waiting queue

Schedulers in Process Management

A scheduler decides which process should move from one stage to another. Different schedulers work at different levels of the operating system.

Scheduler Role Frequency
Long-term scheduler Selects jobs from disk and loads them into memory Runs less frequently
Short-term scheduler Selects the next ready process to run on the CPU Runs very frequently
Medium-term scheduler Temporarily swaps processes out of memory and brings them back later Runs when memory pressure exists

Context Switching

A context switch happens when the CPU stops running one process and starts running another. The OS saves the current process state into its PCB and loads the saved state of the next process.

  1. The running process is interrupted, blocked, or its time quantum expires.
  2. The OS saves the process state, including registers and program counter.
  3. The scheduler chooses another process from the ready queue.
  4. The OS loads the selected process state from its PCB.
  5. The CPU resumes execution of the selected process.

Context switching is necessary for multitasking, but it is also overhead because the CPU spends time switching instead of executing user instructions. A good OS tries to balance responsiveness with switching cost.

Process Creation

A process can create another process. The creating process is called the parent process, and the new process is called the child process. Operating systems use this parent-child relationship to organize and control running tasks.

In Unix and Linux systems, process creation commonly uses fork() and exec().

  • fork() creates a child process by copying the parent process.
  • exec() replaces the child process memory with a new program.
  • wait() lets the parent wait until the child finishes.
  • exit() terminates the current process and returns an exit status.
Unix Process Creation Flow
Parent process
    |
    | fork()
    v
Parent process continues       Child process starts
    |                           |
    | wait()                    | exec()
    |                           v
    |                       New program runs
    |                           |
    |                       exit()
    v
Parent receives child exit status

Process Termination

A process terminates when it finishes normally, encounters an error, is killed by another process, or is stopped by the operating system. After termination, the OS releases the process resources such as memory, open files, and I/O devices.

  • Normal termination: The process completes its task and exits.
  • Error termination: The process stops because of an error such as invalid memory access.
  • Forced termination: Another process or the OS kills it.
  • Cascading termination: Child processes are terminated when the parent process terminates, depending on OS policy.

Zombie and Orphan Processes

Two important special cases in process termination are zombie processes and orphan processes. They are common interview and exam topics.

Type Meaning Why It Happens
Zombie process A child process has finished, but its process table entry still exists The parent has not collected its exit status using wait()
Orphan process A child process is still running after its parent has terminated The parent exits before the child finishes

Interprocess Communication (IPC)

Processes often need to exchange data or coordinate work. Since separate processes usually have separate memory spaces, the OS provides Interprocess Communication, or IPC, mechanisms.

IPC Method How It Works Common Use
Pipes One process writes data and another reads it Command chaining in shells
Message queues Processes exchange structured messages through the OS Producer-consumer communication
Shared memory Multiple processes access the same memory region Fast data sharing
Signals Small notifications sent to a process Stop, terminate, or reload a process
Sockets Processes communicate over a network or local machine Client-server applications

Real-World Process Commands

Different operating systems provide tools to view and manage processes. These commands help users and administrators inspect CPU usage, memory usage, process IDs, and parent-child relationships.

System Command or Tool Purpose
Linux / Unix ps Shows current processes
Linux / Unix top or htop Shows live process CPU and memory usage
Linux / Unix kill Sends a signal to a process
Windows Task Manager Graphical tool for viewing and ending processes
Windows tasklist and taskkill Command-line tools for listing and terminating processes

Common Process Management Problems

  • Starvation: A process waits for a very long time because other processes keep getting CPU time first.
  • Deadlock: Processes wait forever for resources held by each other.
  • Too many context switches: CPU time is wasted switching instead of executing useful work.
  • Resource leak: A process does not release memory, file handles, or other resources properly.
  • Zombie accumulation: Parent processes fail to collect child exit statuses.

Process Management Summary

Concept Remember This
Process A program in execution
PCB Stores all information needed to manage and resume a process
Ready state Process is waiting for CPU time
Waiting state Process is waiting for I/O or another event
Context switch Saves one process state and loads another process state
IPC Allows processes to communicate and synchronize

Frequently Asked Questions

Key Takeaways
  • A process is a program in execution, while a program is passive code stored on disk.
  • The Process Control Block stores the state and management information of each process.
  • Common process states are new, ready, running, waiting, and terminated.
  • The short-term scheduler chooses which ready process gets the CPU next.
  • A context switch saves the current process state and loads another process state.
  • IPC mechanisms such as pipes, shared memory, signals, and sockets allow processes to communicate.

Level Up Your Operating system Skills

Master Operating system with these hand-picked resources

10,000+ learners
Free forever
Updated 2026

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.