Definition
A process can be thought of as a task or job in the system. Process Management is the set of OS functions that handle creation, scheduling, execution, context switching, synchronization, and termination of processes. The OS manages thousands of processes efficiently while maintaining system stability and fairness.
Process Control Block (PCB)
Also called Task Control Block (TCB), this is a data structure maintained by OS for every process.
What Information is Stored in PCB?
- Process ID (PID): Unique identifier for each process
- Process State: Current state (new, ready, running, waiting, terminated)
- Program Counter (PC): Memory address of next instruction to execute
- CPU Registers: Current values of all CPU registers (for context switching)
- Memory Information: Base address, limit, page tables, segment tables
- Priority: Scheduling priority level
- I/O Status: List of open files, I/O devices allocated
- Accounting Information: CPU time used, real time elapsed, memory used
- CPU Scheduling Information: Scheduling queue pointers, CPU burst time prediction
- Signals: Pending signals for the process
- Parent/Child Process: Process relationships
- Resource Pointers: Links to allocated resources
Why PCB?
When a process is interrupted, the OS saves its PCB. When resumed, OS restores PCB to restore exact state before interruption.
Process Creation
When is a Process Created?
- System Boot: System processes (init, shell, services)
- User Request: User clicks on application icon
- System Call: Running process creates child process using
fork()orexec() - Batch Job: Scheduled job starts automatically
Process Creation Steps
- Get Process ID: Assign unique PID
- Allocate Memory: Allocate code, data, heap, stack segments
- Initialize PCB: Create and fill Process Control Block with initial values
- Set Scheduling Parameters: Assign priority, scheduling queue
- Open Files: Open standard input, output, error streams
- Link to Parent: If child process, establish parent-child relationship
- Place in Queue: Place in ready queue for scheduling
- Return to Caller: Parent process gets child’s PID
Parent and Child Processes
When Parent Creates Child
-
Fork() System Call (Unix/Linux):
- Parent process calls
fork() - Child process created as exact copy of parent
- Both continue execution after fork() call
- Child gets own PID, but same program counter position
- Returns child’s PID to parent, 0 to child
- Parent process calls
-
Exec() System Call:
- Child calls
exec()to load new program - Child’s memory replaced with new program
- Child now runs different code than parent
- Child calls
Process Relationships
- Parent Process: Process that creates another process
- Child Process: Process created by another process
- Orphan Process: Child whose parent terminates before child
- Zombie Process: Child that finished but parent hasn’t retrieved status
Process Termination
When Process Terminates?
- Normal Exit: Process completes successfully, calls
exit() - Error Exit: Error condition, process terminates
- Fatal Error: Division by zero, memory access violation
- Killed by Another Process: Parent or system kills process
Termination Steps
- Close Files: All open files closed
- Release Memory: All allocated memory freed
- Deallocate PCB: Process Control Block deleted
- Adjust Relationships: If parent waits, return exit code; if not, become zombie briefly
- Update Parent: Parent notified of termination
- Cascade Termination: If process has children, may terminate them too
Context Switching
What is Context?
All information about a process stored in its PCB (CPU registers, program counter, memory info, etc.).
Context Switch Steps
- Save Context: OS saves CPU registers, PC, memory info to PCB of running process
- Update PCB: Mark process as not running, update its state
- Select Next: Scheduler selects next process from ready queue
- Load Context: Load PCB of selected process into CPU registers
- Start Execution: Jump to program counter address and resume
Context Switch Time
Pure Switching Time: 1-1000 microseconds (CPU-dependent)
Total Context Switch Time:
- Time to save/restore context
- Time for scheduler to select next process
- Time for memory management (cache misses, TLB flushes)
- Can be 10-100 microseconds on modern CPUs
Context Switch Overhead
During context switch, no user process executes. High context switch overhead can reduce efficiency:
- Too many processes → Too many switches → Overhead increases
- OS must balance number of processes vs. switching overhead
Key Operations
1. Process Creation
- Uses
fork()in Unix/Linux,CreateProcess()in Windows - Creates PCB and allocates resources
2. Process Scheduling
- Scheduler selects next process from ready queue
- Uses scheduling algorithm (FCFS, SJF, etc.)
3. Process Context Switch
- Save state of current process
- Load state of next process
- Resume execution
4. Process Communication
- Processes communicate via pipes, sockets, shared memory
- OS provides inter-process communication mechanisms
5. Process Synchronization
- Coordinate processes accessing shared resources
- Use locks, semaphores, condition variables
Advantages of Process Isolation
- Protection: One process crash doesn’t affect others
- Security: One process can’t access another’s memory
- Stability: Faulty process can be terminated independently
- Concurrency: Multiple processes run truly independently
- Resource Management: Each process has own resources
- Privilege Separation: Different privilege levels possible
Disadvantages
- Overhead: Context switching between processes is expensive
- Communication Complexity: Inter-process communication harder than thread communication
- Memory Usage: Each process needs separate memory space
- Slow Creation: Creating new process slower than creating thread
- Slow Context Switch: Process context switching slower than thread switching
Summary
Process management is core OS responsibility. Through PCB, processes can be created, scheduled, switched, and terminated efficiently. Understanding process management is essential for understanding OS scheduling, synchronization, and resource allocation mechanisms.