Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

Process Management in OS — PCB, States, Context Switch | Tutorials Logic

Process vs Program

FeatureProgramProcess
DefinitionA passive entity - a set of instructions stored on diskAn active entity - a program in execution
StorageStored on disk (secondary memory)Loaded in RAM (primary memory)
LifetimePermanent (until deleted)Temporary (exists while running)
ResourcesNo resources allocatedHas CPU, memory, I/O resources
Multiple instancesOne copy on diskMultiple processes from one program

Process Control Block (PCB)

The OS maintains a data structure called the Process Control Block (PCB) for each process. It contains all information about a process:

  • Process ID (PID): Unique identifier for the process
  • Process State: Current state (new, ready, running, waiting, terminated)
  • Program Counter: Address of the next instruction to execute
  • CPU Registers: Contents of all CPU registers (saved during context switch)
  • Memory Management Info: Base/limit registers, page tables
  • I/O Status: List of I/O devices allocated, open files
  • Accounting Info: CPU time used, time limits, process priority
  • Parent PID: PID of the parent process

Process States

A process transitions through the following states during its lifetime:

  • New: Process is being created. PCB is being initialized.
  • Ready: Process is loaded in memory and waiting for CPU time. In the ready queue.
  • Running: Process is currently executing on the CPU. Only one process per CPU core can be in this state.
  • Waiting (Blocked): Process is waiting for an event (I/O completion, signal, resource). Cannot use CPU.
  • Terminated: Process has finished execution. Resources are being released.

State Transitions:

  • New -> Ready: Process admitted to ready queue
  • Ready -> Running: Scheduler dispatches process to CPU
  • Running -> Ready: Preempted (time quantum expired or higher priority process arrives)
  • Running -> Waiting: Process requests I/O or waits for event
  • Waiting -> Ready: I/O completes or event occurs
  • Running -> Terminated: Process completes or is killed

Context Switching

When the OS switches the CPU from one process to another, it performs a context switch:

  1. Save the state of the current process (registers, program counter) into its PCB
  2. Load the state of the next process from its PCB
  3. Resume execution of the next process

Context switching is pure overhead - no useful work is done during the switch. Modern CPUs have hardware support to speed up context switches.

Process Creation and Termination

Process Creation (fork()): In Unix/Linux, a new process is created using the fork() system call. The parent process creates a child process that is an exact copy of the parent. The child then typically calls exec() to replace its memory with a new program.

  • fork() returns 0 to the child, and the child's PID to the parent
  • Parent and child run concurrently after fork()
  • Parent can wait for child using wait()

Zombie Process: A process that has completed execution but its entry still exists in the process table because the parent hasn't called wait() yet.

Orphan Process: A process whose parent has terminated. The orphan is adopted by the init process (PID 1).


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.