An operating system's core job is to let many programs share one CPU and one memory without destroying each other. The three ideas that make that work are processes (programs in execution, isolated from each other), threads (cheap execution units inside a process), and scheduling (the policy that decides who runs next). This guide covers the definitions examiners actually ask about, plus the numerical scheduling problems that appear in BSc OS papers and computer-awareness sections of banking and SSC exams.
What a process really is
A program is a passive file on disk. A process is that program in execution: code, current activity (the program counter value), and a set of resources. The OS tracks every process in a Process Control Block (PCB) containing:
- Process ID and state (new, ready, running, waiting, terminated)
- Program counter and CPU register values
- Memory-management info (page tables / segment tables)
- Open file handles, I/O status
- Scheduling info (priority, accounting)
The five process states
New → Ready → Running → Terminated
↑ ↓
← Waiting ←
- New: being created; the PCB is being built.
- Ready: waiting in the ready queue for CPU time.
- Running: instructions are executing on the CPU (one process per core).
- Waiting (blocked): waiting for an event — disk read, network packet, timer, lock.
- Terminated: finished or killed; resources are being reclaimed.
Transitions exams ask about: Running → Ready (preemption), Running → Waiting (the process requests I/O), Waiting → Ready (the I/O completes).
Processes vs threads
A thread is a basic unit of CPU utilisation inside a process. Threads of one process share the code, data, and open files of that process; each thread keeps its own stack, registers, and program counter.
| Dimension | Process | Thread |
|---|---|---|
| Address space | Own, isolated | Shared with sibling threads |
| Creation cost | Higher (PCB, memory map) | Lower (stack + TCB) |
| Switch cost | Higher (full memory-map switch) | Lower (same map) |
| Communication | IPC needed (pipes, sockets, shared memory files) | Shared variables (needs synchronisation) |
| Crash blast radius | One process | Whole process (all threads) |
| Example | Two browser apps | Tabs of one browser |
Why threads exist: servers keep one thread per connection; browsers keep one per tab; a text editor uses one for spell-check so typing never blocks. Shared memory is also the classic bug source — race conditions — the reason every OS course covers synchronisation.
Context switching: the cost of multitasking
When the scheduler moves the CPU from process A to process B, the kernel must save A's registers and PCB state and restore B's. That is a context switch, and it costs roughly 1-15 microseconds on typical hardware — small per switch, expensive at high rates.
Three exam-worthy facts:
- Context switching time is pure overhead — no user code runs during it.
- Switching between threads of one process is cheaper than between processes (the memory map stays).
- Too-small time quanta cause excess switching; too-large quanta degrade response time — which is why typical Round Robin quanta land in the 10-100 ms range.
CPU scheduling: the algorithms
Assumptions for the problems below: one CPU, all jobs arrive at the time shown, no I/O during bursts. Let us use this five-job batch:
| Job | Arrival | Burst |
|---|---|---|
| P1 | 0 | 7 |
| P2 | 1 | 4 |
| P3 | 2 | 1 |
| P4 | 3 | 4 |
| P5 | 4 | 2 |
FCFS (First Come, First Served)
Non-preemptive: run in arrival order. Order: P1, P2, P3, P4, P5.
| Job | Completion | Turnaround | Waiting |
|---|---|---|---|
| P1 | 7 | 7 | 0 |
| P2 | 11 | 10 | 6 |
| P3 | 12 | 10 | 9 |
| P4 | 16 | 13 | 9 |
| P5 | 18 | 14 | 12 |
Average waiting time = (0+6+9+9+12)/5 = 7.2 ms. One long job at the head (P1) delays everyone — the convoy effect.
SJF (Shortest Job First, non-preemptive)
When a decision point comes, run the shortest available burst. Order: P1 (t=0, only choice) → P3 (1) → P5 (2) → P2 (4) → P4 (4).
| Job | Completion | Turnaround | Waiting |
|---|---|---|---|
| P1 | 7 | 7 | 0 |
| P3 | 8 | 6 | 5 |
| P5 | 10 | 6 | 4 |
| P2 | 14 | 13 | 9 |
| P4 | 18 | 15 | 11 |
Average waiting = (0+5+4+9+11)/5 = 5.8 ms — better than FCFS, as theory predicts (SJF is optimal for average waiting among non-preemptive algorithms). Its practical flaw: the OS does not know burst lengths in advance; it estimates them.
SRTF (Shortest Remaining Time First, preemptive SJF)
At every arrival or completion, run the job with the shortest remaining time. When P2 arrives at t=1, P1 has 6 left and P2 has 4 — preempt P1. When P3 arrives at t=2 (burst 1), it wins immediately. Running order with preemptions: P1(0-1), P2(1-2), P3(2-3), P5(3-5), P2(5-8), P4(8-12), P1(12-18).
Average waiting time = (11+4+0+8+0)/5 = 4.6 ms — the best of the four here, at the cost of preemption overhead and starvation risk for long jobs.
Round Robin (quantum q = 4)
Ready queue cycles, each job runs at most q. Gantt sketch: P1(0-4), P2(4-8, finishes at 8 since burst 4), P3(8-9), P4(9-13), P5(13-15), P1(15-18, 3 left).
Average waiting = ((18-7)+(7-4)+(6-1)+(10-4)+(11-2))/5 = (11+3+5+6+9)/5 = 6.8 ms. RR is designed for response time, not waiting time: every job gets a slice quickly, which is what an interactive system wants.
The exam-proof comparison
| Algorithm | Preemptive? | Avg waiting here | Weakness |
|---|---|---|---|
| FCFS | No | 7.2 ms | Convoy effect |
| SJF | No | 5.8 ms | Needs burst prediction; starvation of long jobs |
| SRTF | Yes | 4.6 ms | Preemption overhead; heavy starvation without aging |
| Round Robin (q=4) | Yes | 6.8 ms | Quantum choice is a trade-off |
What real systems actually do
Linux uses the Completely Fair Scheduler (CFS), which tracks virtual runtime per task and picks the task that has had the least CPU so far — an approximation of fair sharing rather than any of the textbook algorithms alone. Windows uses a multilevel feedback queue with priority classes and priority boosting for interactive threads. Both keep threads near their last core for cache warmth.
Common exam mistakes
- Mixing up waiting and turnaround time. Turnaround = completion − arrival; waiting = turnaround − burst. Students often report completion time as turnaround.
- Forgetting arrival times in SRTF. Re-evaluate remaining time at each arrival, not only at completions.
- Calling SJF preemptive. SJF is non-preemptive by definition; its preemptive version is SRTF (sometimes called "preemptive SJF").
- Assuming RR average waiting is always low. RR trades waiting time for response time; with a large quantum it degenerates to FCFS.
- Describing threads as "lightweight processes" without naming what is shared. Examiners want: shared address space, separate stack/registers.
Practice on PixoQuest
Scheduling questions reward fast, accurate pattern work: name the algorithm, draw the Gantt chart, compute turnaround and waiting. The PixoQuest GK: World and Science course covers computer-awareness fundamentals — processes, memory, and OS basics — through short quiz rounds that fit into a 10-minute break. Use it to drill definitions and comparisons; use a notebook for the full Gantt-chart problems.
Bottom line
A process is an isolated program in execution tracked by a PCB; a thread is a lighter execution unit sharing its process's memory; a context switch costs ~1-15 µs of pure overhead. On scheduling exams, compute turnaround and waiting for FCFS, SJF, SRTF, and Round Robin on the same batch and you will see the theory: SJF minimises average waiting, RR buys fairness with a quantum, and aging prevents starvation. Real kernels mix these ideas — but the exam numbers all come from these four.
Sources & further reading
- Remzi Arpaci-Dusseau, Operating Systems: Three Easy Pieces (free textbook, CPU scheduling and processes chapters): https://pages.cs.wisc.edu/~remzi/OSTEP/
- Silberschatz, Galvin and Gagne, Operating System Concepts (Wiley) — the standard BSc text for process states and scheduling algorithms
- Linux kernel documentation, CFS Scheduler overview: https://docs.kernel.org/scheduler/sched-design-CFS.html
- MIT OpenCourseWare, 6.828 Operating System Engineering (threads, context switches, kernels): https://ocw.mit.edu/courses/6-828-operating-system-engineering-fall-2012/
Waiting/turnaround figures in this article are computed from the five-job example table, not measured on hardware; the 1-15 µs context-switch range is an order-of-magnitude figure that varies by CPU and kernel.
Frequently asked questions
What is the difference between a process and a thread?
A process has its own address space, memory, and resources; a thread shares its process's memory and resources and has its own stack and registers. Threads are cheaper to create and switch between, but a crash in one thread can take down the whole process.
What is a context switch?
The CPU saving the state of one process or thread and loading another — registers, program counter, and related data move to and from the PCB or thread control block. Context switches take roughly 1-15 microseconds on typical hardware and are pure overhead: no user work happens during them.
Which scheduling algorithm is best?
None universally. SJF gives the minimum average waiting time for a known batch but is impractical (burst times are unknown); Round Robin gives fair response times; modern systems use multilevel feedback queues that adapt. Exams usually test how to compute waiting and turnaround time for FCFS, SJF, SRTF, and RR.
What is the difference between preemption and non-preemption?
A non-preemptive algorithm (FCFS, non-preemptive SJF) lets a process keep the CPU until it blocks or finishes. A preemptive one (SRTF, Round Robin, priority with preemption) can take the CPU away — better response, more context-switch overhead.
What causes starvation and how is it fixed?
Starvation happens when low-priority processes wait indefinitely under priority or SJF-style scheduling. The standard fix is aging: gradually raise the priority of waiting processes so every job eventually runs.