Operating System - Operations on Process in Operating System
A process is a running instance of a program. The Operating System manages processes by performing various operations on them during their lifecycle.
1. Process Creation
-
A new process is created when:
-
A program is started.
-
An existing process (parent) creates another process (child).
-
-
In Unix/Linux, this is done using the
fork()
system call.
Example: Opening a browser creates a new browser process.
OS actions:
-
Assign a unique Process ID (PID)
-
Allocate memory
-
Initialize PCB (Process Control Block)
-
Load program code into memory
-
Add the process to the ready queue
2. Process Scheduling
-
The OS schedules processes using a scheduler.
-
It selects one of the ready processes for CPU execution.
-
Uses algorithms like FCFS, Round Robin, Priority Scheduling, etc.
OS actions:
-
Dispatch the selected process
-
Load its context (CPU registers, program counter)
-
Start or resume execution
3. Process Switching (Context Switching)
-
When the CPU switches from one process to another:
-
It saves the state of the current process
-
Loads the state of the next process
-
OS actions:
-
Save PCB of current process
-
Load PCB of the next process
-
Restore CPU context
4. Process Suspension and Resumption
-
A process can be suspended temporarily (e.g., for I/O wait or to free resources).
-
It can be resumed later.
OS actions:
-
Move process to suspended state
-
Retain its context
-
Resume later from the same point
5. Process Termination
-
A process is terminated when:
-
It completes execution successfully
-
It is killed by the user or OS due to an error or violation
-
OS actions:
-
Release all resources (memory, I/O)
-
Remove PCB
-
Notify parent process (if any)
Example: Closing a game ends its process and frees up RAM.
6. Inter-Process Communication (IPC)
-
Processes may need to communicate and share data.
-
OS provides mechanisms like:
-
Shared memory
-
Message passing
-
Pipes and sockets
-
OS actions:
-
Synchronize processes
-
Manage safe access to shared data