1. What is an Operating System? Explain its purpose and functions.
An operating system is system software that sits between the hardware and the applications. Its job is to manage the hardware — CPU, memory, disk, devices — and provide services that programs (and users) rely on.
What it does:
- Process management — creates, schedules, and terminates processes.
- Memory management — allocates RAM, handles virtual memory.
- File system — organizes data on disk into files and folders.
- Device management — drivers let the OS talk to keyboards, disks, printers.
- Security — protects one process from another and users from each other.
Think of it as the middleman: the application asks for a file or more memory, and the OS negotiates with the hardware to deliver it.
+----------------------+
| APPLICATIONS |
| Browser | Editor | DB |
+----------+-----------+
|
v
+----------------------+
| OPERATING SYSTEM |
| Process Management |
| Memory Management |
| File System |
| Device Management |
| Security |
+----------+-----------+
|
v
+----------------------+
| HARDWARE |
| CPU | RAM | Disk | I/O|
+----------------------+
2. What is a Kernel? How do Monolithic and Microkernel architectures differ?
The kernel is the core of the operating system — the part always in memory, with full control over the hardware. Everything else (shell, apps, utilities) is less privileged.
The difference between architectures is where services run:
- Monolithic kernel — all core services (scheduling, file systems, drivers, networking) run in kernel space. Fast, since everything is one big program with no message-passing overhead. Linux is the classic example. The downside: a bug in one driver can crash the whole system.
- Microkernel — only the essentials (process scheduling, basic memory, IPC) stay in kernel space. File systems, drivers, and other services run in user space and talk to the kernel via messages. More robust — a crashed driver doesn’t take down the OS — but slower due to the message-passing. MINIX and QNX are examples.
Trade-off in one line: monolithic is fast but fragile; microkernel is safe but has overhead.
MONOLITHIC KERNEL
+-----------------------------------+
| KERNEL SPACE |
| |
| +---------+ +---------+ |
| |Scheduler| | Memory | |
| +---------+ +---------+ |
| +---------+ +---------+ |
| |File Sys | | Drivers | |
| +---------+ +---------+ |
| +---------+ |
| |Network | |
| +---------+ |
+-----------------------------------+
|
v
Hardware
MICROKERNEL
+----------------------+ +----------------------+
| KERNEL SPACE | | USER SPACE |
| | | |
| Scheduler | | File System |
| Basic Memory |<->| Drivers |
| IPC | | Networking |
+----------------------+ +----------------------+
|
v
Hardware
3. What is Virtual Memory? How does it work?
Virtual memory lets programs run as if the machine had more RAM than it actually does. It uses disk space (swap) as an extension of physical memory.
How it works:
- Each process gets a large, fake address space (virtual addresses).
- The CPU + MMU translate virtual addresses to physical RAM addresses on the fly.
- When a program touches an address not currently in RAM, the OS loads that page from disk — called a page fault.
This means a program can be bigger than physical memory: only the pages being actively used sit in RAM, the rest wait on disk.
The benefit: process isolation (each program thinks it owns the whole address space), running large programs, and overcommitting memory across many processes.
PROCESS
Virtual Address
|
v
+-------+
| MMU |
+---+---+
|
+----+----+
| |
v v
Page Table Page Fault
| |
v v
Physical OS loads
RAM page from
| disk
| |
+-----+----+
v
CPU runs
4. Explain Paging vs. Segmentation.
Both are memory management techniques, but they split memory differently.
- Paging — divides memory into fixed-size blocks. Physical memory is split into frames (say 4KB), virtual memory into pages of the same size. A page table maps pages to frames. Because blocks are fixed, there’s no external fragmentation.
- Segmentation — divides memory into variable-sized logical units that reflect the program’s structure: a segment for code, one for data, one for the stack. Segments can differ in size, matching real program layout — but variable sizes cause fragmentation.
PAGING
Virtual Memory Physical Memory
+------+ +------+
|Page 0| -----------------> |Frame3|
+------+ +------+
|Page 1| -----------------> |Frame0|
+------+ +------+
|Page 2| -----------------> |Frame5|
+------+ +------+
|Page 3| -----------------> |Frame1|
+------+ +------+
Fixed-size blocks
|
v
Page Table maps Page -> Frame
SEGMENTATION
Program
+----------------+
| Code | <- Variable size
+----------------+
| Data | <- Variable size
+----------------+
| Stack | <- Variable size
+----------------+
Logical units match program structure.
| Paging | Segmentation | |
|---|---|---|
| Unit size | Fixed (pages/frames) | Variable (segments) |
| Matches program structure | No | Yes |
| External fragmentation | None | Possible |
| Visibility to programmer | Hidden | Visible |
Modern systems typically combine them — paged segments.
5. What are Process States? Explain the Process Control Block (PCB).
A process moves through a standard lifecycle of states:
- New — just created, being initialized.
- Ready — loaded and waiting for the CPU.
- Running — currently executing on a core.
- Waiting (Blocked) — paused, waiting for an event or I/O.
- Terminated — finished, resources being reclaimed.
+-------+
| New |
+---+---+
|
v
+-------+
| Ready |<----------------+
+---+---+ |
| |
Dispatch | I/O
| | Complete
v |
+---------+ |
| Running |----------------+
+----+----+
| |
I/O Request | Exit
| |
v v
+---------+ +-----------+
| Waiting | | Terminated|
+---------+ +-----------+
The PCB (Process Control Block): the kernel’s data structure that holds everything the OS knows about a process:
- PID (process ID) and parent PID
- Process state (which of the above it’s in)
- Registers and program counter (to resume exactly where it left off)
- Memory limits and page table
- List of open files
- Scheduling information (priority, time used)
+----------------------------------+
| PROCESS CONTROL BLOCK |
+----------------------------------+
| PID / Parent PID |
| Process State |
| Program Counter |
| CPU Registers |
| Memory / Page Table |
| Open Files |
| Scheduling Information |
+----------------------------------+
Each process has exactly one PCB — the “ID card” the scheduler and other subsystems use.
6. What is Demand Paging?
Demand paging means pages are brought into memory only when they’re actually referenced — not all at the start.
Without it, a program would load its entire image into RAM before running, wasting time and memory on pages that may never be used.
How it works:
- The process starts with none (or few) of its pages in RAM.
- The first time it touches a missing page, the CPU raises a page fault.
- The OS loads just that page from disk, updates the page table, and resumes the process.
Program starts
|
v
+-------------------+
| Page is in RAM ? |
+---------+---------+
|
+--+--+
Yes No
| |
v v
Continue Page Fault
|
v
+-----------+
| OS loads |
| page from |
| disk |
+-----+-----+
|
v
Update Page Table
|
v
Resume
The first access is slow (page fault + disk read), but overall the program starts fast and only loads what it needs. That’s why a huge application can launch quickly — most of it never gets loaded.
7. Explain CPU Scheduling Algorithms: FCFS, SJF, Round Robin, Priority.
- FCFS (First Come First Served) — processes run in arrival order. Simple and fair, but short jobs stuck behind a long one cause the “convoy effect.”
- SJF (Shortest Job First) — picks the process with the shortest CPU burst next. Minimizes average waiting time, but you must know burst lengths in advance — and long jobs can starve.
- Round Robin (RR) — each process gets a fixed time slice (quantum), then moves to the back of the queue. Great for responsiveness; the quantum size matters — too small = too many switches, too big = degrades toward FCFS.
- Priority Scheduling — the highest-priority process runs first. Efficient but risks starvation of low-priority tasks; solved with aging (priorities rise over time).
FCFS
Ready Queue
+---+---+---+
| P1| P2| P3|
+---+---+---+
|
v
+----+----+----+
| P1 | P2 | P3 |
+----+----+----+
SJF
Ready Queue
+---+---+---+
| P1| P2| P3|
+---+---+---+
| shortest burst first
v
+----+----+----+
| P2 | P3 | P1 |
+----+----+----+
ROUND ROBIN
+----+----+----+
| P1 | P2 | P3 |
+----+----+----+
^ |
|_________|
Time Quantum
PRIORITY
+---------+
| Highest |
| Priority|
+----+----+
|
v
CPU
^
|
+----+----+
| Lowest |
| Priority|
+---------+
| Algorithm | Order | Starvation risk | Best for |
|---|---|---|---|
| FCFS | Arrival | No | Batch, simple |
| SJF | Shortest burst | Yes (long jobs) | Minimizing wait |
| Round Robin | Time slices | No | Interactive systems |
| Priority | Highest priority | Yes (low priority) | Real-time systems |
8. What is the Banker’s Algorithm?
The Banker’s Algorithm is a deadlock avoidance method. Before granting a resource request, it simulates the allocation and checks whether the resulting state is safe — meaning every process can still finish without deadlock.
The idea (why “banker”): like a banker lending money, the OS never grants a request if doing so would leave the system unable to satisfy any future request.
Steps:
- A process requests resources.
- The OS pretends to grant them.
- It runs the safety check: can at least one process finish and release everything? Then another? And so on?
- If yes → the state is safe, grant the request. If no → make the process wait.
Resource Request
|
v
+-------------------+
| Pretend to Grant |
| Resources |
+---------+---------+
|
v
+-------------------+
| Safety Check |
| |
| Can processes |
| still finish? |
+---------+---------+
|
+-----+-----+
Yes No
| |
v v
+-------------+ +--------+
| Grant | | Wait |
| Request | | Request|
+-------------+ +--------+
The catch: it needs to know each process’s maximum resource need in advance, which is often impractical — that’s why it’s taught but rarely used in real systems.
9. What is Thrashing? Why does it occur?
Thrashing is a state where the system spends more time swapping pages in and out of memory than actually executing code.
Why it happens: The system has too many active processes, and their combined working sets don’t fit in RAM. Every process constantly page-faults. The CPU’s response to a fault is to load from disk, but while it waits, another process faults, and so on. Disk I/O saturates and CPU utilization drops to near zero — even though the machine looks “busy.”
The vicious cycle:
Low CPU Utilization
|
v
OS adds more processes
|
v
Less RAM per process
|
v
More Page Faults
|
v
More Disk I/O
|
v
Lower CPU Utilization
|
+------------------+
|
v
THRASHING
Fixes:
- Reduce the degree of multiprogramming (fewer active processes).
- Use the working-set model to keep only processes whose pages fit.
- Add more physical memory or increase the page size.
Thrashing isn’t a hardware failure — it’s a symptom of memory pressure.
10. What is Deadlock? Explain its conditions and prevention.
A deadlock is a permanent block where a set of processes each holds a resource and waits for a resource another process holds — so none can proceed.
Four necessary conditions (all four must hold):
- Mutual Exclusion — resources can’t be shared (only one process at a time).
- Hold & Wait — a process holds some resources while waiting for others.
- No Preemption — resources can’t be forcibly taken away.
- Circular Wait — a cycle of processes, each waiting for a resource held by the next.
+---------+ +---------+
| Process | | Process |
| P1 | | P2 |
+----+----+ +----+----+
| |
| Holds Resource A | Holds Resource B
| |
v v
+---------+ +---------+
| A | | B |
+---------+ +---------+
^ ^
| |
| Waiting for B | Waiting for A
| |
+-----------------------------------+
DEADLOCK
A clearer representation of the circular wait is:
P1
/ \
Holds A Waits for B
| |
v v
A B
^ ^
| |
Waits for A Holds B
\ /
P2
P1 -> B -> P2 -> A -> P1
CIRCULAR WAIT
Prevention: break any one condition:
- Break Mutual Exclusion — not always possible (some resources are inherently exclusive).
- Break Hold & Wait — require processes to request all resources upfront.
- Break No Preemption — allow the OS to preempt resources.
- Break Circular Wait — impose a global resource ordering so requests always go in increasing order.
Since prevention is restrictive, many real systems instead avoid (Banker’s) or detect + recover (kill a victim, roll back).
DEADLOCK HANDLING
|
+--------------+--------------+
| | |
v v v
Prevention Avoidance Detection
| | |
v v v
Break a condition Banker's Detect cycle
|
v
Recovery
(kill / rollback)Premium Content
Unlock Core High-Frequency Concepts and all premium lessons with a subscription.
From ₹199.99/year — See plans