Define a process in an operating system. Explain CPU scheduling in process management and describe the major CPU scheduling algorithms used in operating systems.
10 marks
Question source
- Exam year
- 2083 BS / 2026 AD
- Level
- Fifth Level
- Paper
- Paper II – Information Technology and Management
- Section
- Section C: Long Answer Questions
Model answer
Process in an Operating System
A process is a program in execution. While a program is a static set of instructions stored on disk, a process is an active entity — the program loaded into memory and being executed by the CPU.
A process includes:
- Program code (text section) — the executable instructions
- Program counter — address of the next instruction to execute
- Stack — temporary data (function parameters, return addresses, local variables)
- Heap — dynamically allocated memory during runtime
- Data section — global and static variables
- Process Control Block (PCB) — OS data structure storing process state, ID, registers, priority, etc.
Process States: New → Ready → Running → Waiting → Terminated
CPU Scheduling in Process Management
CPU scheduling is the OS function of deciding which process in the Ready Queue gets CPU time, when, and for how long. Since only one process can run on one CPU core at a time, the scheduler must manage multiple ready processes efficiently.
Objectives of CPU scheduling:
- Maximize CPU utilization — keep CPU busy as much as possible
- Maximize throughput — number of processes completed per unit time
- Minimize turnaround time — total time from submission to completion
- Minimize waiting time — time a process spends in the ready queue
- Minimize response time — time from request until first response
- Fairness — each process gets a fair share of CPU time
Types of scheduling:
- Non-preemptive — once a process starts running, it runs until it voluntarily gives up the CPU (I/O request or completion)
- Preemptive — the OS can forcibly remove a running process from the CPU and assign it to another
Major CPU Scheduling Algorithms
1. First Come First Served (FCFS)
Processes are executed in the order they arrive in the ready queue. Non-preemptive.
| Process | Arrival | Burst | Completion | Turnaround | Waiting |
|---|---|---|---|---|---|
| P1 | 0 | 5 | 5 | 5 | 0 |
| P2 | 1 | 3 | 8 | 7 | 4 |
| P3 | 2 | 8 | 16 | 14 | 6 |
- Advantage: Simple, easy to implement, no starvation
- Disadvantage: Convoy effect — a long process holds up all shorter processes behind it; poor average waiting time
2. Shortest Job First (SJF)
The process with the shortest CPU burst time is scheduled next. Non-preemptive.
- Advantage: Provably optimal average waiting time for a given set of processes
- Disadvantage: Starvation — long processes may wait indefinitely if shorter processes keep arriving; difficult to predict CPU burst time in advance
3. Shortest Remaining Time First (SRTF)
Preemptive version of SJF. If a new process arrives with a shorter remaining burst time than the currently running process, the CPU is preempted.
- Advantage: Even better average waiting time than SJF
- Disadvantage: High overhead from frequent context switches; starvation possible
4. Round Robin (RR)
Each process is given a fixed time quantum (e.g., 10ms). After its quantum expires, the process is preempted and placed at the back of the ready queue. The next process in queue gets the CPU.
Example: With time quantum = 4ms and processes P1(5ms), P2(3ms), P3(8ms):
-
P1 runs 4ms → preempted; P2 runs 3ms → done; P1 runs 1ms → done; P3 runs 4ms → preempted; P3 runs 4ms → done
-
Advantage: Fair CPU distribution; good response time for interactive users; no starvation
-
Disadvantage: Performance depends heavily on time quantum choice; high context switch overhead if quantum is too small
-
Most widely used in time-sharing and interactive operating systems (Linux, Windows)
5. Priority Scheduling
Each process is assigned a priority number. The process with the highest priority (lowest number, typically) runs first. Can be preemptive or non-preemptive.
- Advantage: Important processes (real-time, system processes) get CPU first
- Disadvantage: Starvation — low-priority processes may never run
- Solution: Aging — gradually increase the priority of processes that wait too long
6. Multilevel Feedback Queue (MLFQ)
The most sophisticated practical scheduler. Multiple queues exist with different priority levels and time quanta (higher queues have shorter quanta). Processes move between queues based on their behavior:
-
New processes enter the highest-priority queue (short quantum)
-
If they exhaust their quantum (CPU-bound), they are moved to a lower-priority queue (longer quantum)
-
If they block for I/O frequently (I/O-bound), they remain in or move to higher-priority queues
-
Advantage: Automatically adapts to process behavior; interactive processes (I/O-bound) get good response time; CPU-bound batch processes are served efficiently in lower queues
-
Used in: Linux (CFS with scheduling classes), Windows (foreground/background priority)
| Algorithm | Preemptive? | Starvation? | Best For |
|---|---|---|---|
| FCFS | No | No | Batch systems, simple queues |
| SJF | No | Yes | Batch with known burst times |
| SRTF | Yes | Yes | Minimizing average wait |
| Round Robin | Yes | No | Time-sharing, interactive systems |
| Priority | Both | Yes (without aging) | Real-time, priority-based systems |
| MLFQ | Yes | No (with aging) | General-purpose OS |