Chapter 01 · OS
OS Structures & System Calls
4 topics · 1 sections · beginner-friendly study notes · Updated
An operating system manages hardware and gives programs a safe, uniform interface.
This chapter covers OS roles, the user/kernel split with dual-mode protection, system calls, monolithic vs microkernel designs, and how interrupts and traps transfer control into the kernel.
Every OS paper opens here.
GATE regularly asks which instructions are privileged, what happens on a system call, and how microkernels differ from monolithic kernels.
Linux/Windows internals, container isolation, device drivers, writing safe system software, and debugging syscall-heavy programs with tools like strace.
OS Overview & Types
An operating system is system software that manages hardware resources (CPU, memory, storage, I/O devices), provides abstractions (processes, files, virtual memory) and enforces protection between users and programs.
In short: The OS is the manager that shares the machine fairly and hides messy hardware details from programs.
Think about it
Without an OS each application would need its own drivers and could corrupt others’ memory. Two apps can run at the same time on one laptop without overwriting each other’s memory because the OS isolates them.
Two classic views
- 1resource manager - allocate CPU time, memory and devices among competing programs;
- 2extended machine - present a simpler interface such as files instead of disk blocks.
Core functions: process management, memory management, file system, I/O management, protection/security, and user interface.
Goals differ by type: batch (throughput), time-sharing (response time), real-time (deadline guarantees), distributed (resource sharing).
Key points
- Kernel: Core part of the OS that runs in privileged mode.
- Multiprogramming: Several programs kept in memory so the CPU stays busy when one waits for I/O.
- Time-sharing: Multiprogramming plus frequent switching so users see interactive response.
- Spooling: Overlapping I/O of one job with computation of others using a disk buffer (e.g. print queue).
- Types of OS: Batch (jobs grouped, no interaction), Multiprogrammed (several jobs in memory), Time-sharing/multitasking (quantum-based, interactive), Real-time (hard/soft deadlines), Distributed (many machines appear as one), Network OS, Embedded and Mobile OS (Android, iOS), Multiprocessor/parallel (symmetric vs asymmetric).
- Degree of multiprogramming = number of processes in memory; CPU utilization = 1 − p^n for n processes each waiting for I/O a fraction p of the time (e.g. p = 0.8, n = 4 gives 1 − 0.4096 ≈ 59%).
- Multiprogramming raises CPU utilization; time-sharing improves response time.
- Real-time OS: hard (missing a deadline is failure) vs soft (late result degrades value).
User Mode vs Kernel Mode
Hardware provides a mode bit: kernel (supervisor) mode allows all instructions; user mode forbids privileged instructions such as I/O, setting the timer, modifying page tables, and disabling interrupts.
In short: Ordinary programs run in a restricted sandbox; only the kernel may touch hardware directly.
Think about it
If any program could disable interrupts or write to the disk controller, one bug could crash or hijack the whole system.
Dual-mode operation protects the OS from user programs.
Attempting a privileged instruction in user mode raises a trap and the OS usually terminates the process.
A timer interrupt ensures the OS regains the CPU even if a user program loops forever.
Memory protection (base/limit or paging) prevents a process from reading kernel or other process memory.
Switching user→kernel happens only through controlled entry points: system call, interrupt or exception, never by a user program simply setting the mode bit.
Key points
- Mode bit: Hardware flag: 0 = kernel, 1 = user (convention varies).
- Privileged instruction: Instruction that executes only in kernel mode.
- Trap: Synchronous software-generated transfer into the kernel.
- Privileged: set timer, clear memory, disable interrupts, I/O instructions, change mode bit, modify memory-management registers.
- NOT privileged: read the clock, issue a system call (trap) instruction, normal arithmetic and load/store in own address space.
System Calls & fork()
A system call is the programmatic interface through which a user program requests a service from the kernel. It executes a trap instruction that switches to kernel mode and jumps to a handler selected by a system-call number.
In short: It is the polite way for a program to say: kernel, please open this file or create this process for me.
Think about it
System calls are the only controlled gateway between untrusted user code and privileged kernel services.
Typical flow
the program calls a library wrapper (e.
g.
read in libc) → arguments and the call number are placed in registers or on the stack → trap instruction → kernel looks up the number in the system call table → kernel validates arguments and does the work → result placed in a register → return to user mode.
Parameters can be passed in registers, in a memory block (address in a register), or on the stack.
Categories
process control (fork, exec, exit, wait), file management (open, read, write, close), device management (ioctl), information maintenance (getpid, time), communication (pipe, socket, shmget), protection (chmod).
An API such as printf is a library function that may eventually call the write system call; a library call is not always a system call.
Key points
- System call table: Kernel array mapping call numbers to handler functions.
- Wrapper / API: Library function (libc) that prepares arguments and issues the trap.
- Context of call: Register state saved so the user program resumes after the call.
fork()is the system call that creates a new process: it returns 0 to the child, the child PID (> 0) to the parent and -1 on failure. Child gets a copy of the parent address space (copy-on-write) and the same open files.- Counting rule: n unconditional
fork()calls in sequence create 2^n processes in total (2^n − 1 new children). Example:fork();fork();printf("A"); prints A four times. - Mode switch cost: a system call needs a user
→kernel trap, argument validation andreturn, so it is much cheaper than a context switch but costlier than a normal function call. - Output example: int
main(){if(fork()==0)printf("C "); elseprintf("P "); } prints "P C" or "C P" (order not guaranteed).
Example
CodeC example with system calls:
#include <unistd.h>
#include <fcntl.h>
int main(void) {
int fd = open("data.txt", O_RDONLY); // system call (via wrapper)
char buf[16];
ssize_t n = read(fd, buf, sizeof buf); // system call
write(1, buf, n); // write to stdout (fd 1)
close(fd); // system call
return 0;
}
/* strace ./a.out shows open, read, write, close syscalls */Monolithic vs Microkernel
Monolithic: the whole OS runs as a single large program in kernel space. Layered: OS divided into layers, each using only the layer below. Microkernel: only minimal services (IPC, basic scheduling, low-level memory) in the kernel; file systems, drivers and networking run as user-space servers.
In short: Monolithic = everything in the kernel (fast, riskier). Microkernel = tiny kernel, services outside (safer, more message passing).
Think about it
The design decides performance, reliability and how easily the OS can be extended.
Monolithic kernels (classic Unix, Linux) make calls between components as plain function calls, giving speed, but a faulty driver can crash the whole system.
Linux mitigates size with loadable kernel modules.
Layered design gives modularity and easy debugging but is hard to define layers cleanly and may be slower.
A microkernel (Mach, QNX, MINIX) gains reliability, security and extensibility since a crashed driver server can be restarted, but communication between servers uses message passing through the kernel, adding overhead.
Hybrid kernels (Windows NT, macOS XNU) mix both ideas.
Key points
- IPC: Inter-process communication, typically message passing in microkernels.
- Loadable module: Kernel code added or removed at run time without rebooting.
- Hybrid kernel: Microkernel-like structure with many services still in kernel space for speed.
- Microkernel: + easier to extend and port, + more secure and reliable, - performance overhead from user↔kernel message copies.
- Monolithic: + speed, - larger attack surface and hard to maintain.
Interrupts, traps and exceptions
An interrupt is an asynchronous signal from hardware (I/O completion, timer) that makes the CPU save its state and run an interrupt service routine (ISR). A trap or exception is synchronous and caused by the executing instruction (system call, divide by zero, page fault, illegal instruction).
In short: Interrupt = a device taps the CPU on the shoulder. Trap = the running program itself causes the switch.
Think about it
Interrupts avoid wasteful polling and let the OS keep control of the CPU through the timer.
Steps on interrupt
finish current instruction → save PC/flags (and mode) → look up the ISR address in the interrupt vector table using the interrupt number → run ISR in kernel mode → restore state and resume.
Interrupts can be masked (disabled) by the kernel for critical sections, except the non-maskable interrupt (NMI) used for severe hardware errors.
Priorities let urgent interrupts preempt lower ones.
A page fault is an exception that the OS handles and then re-executes the faulting instruction.
I/O methods: programmed I/O (polling), interrupt-driven I/O, and DMA where the controller transfers a block to memory and interrupts once at the end.
Key points
- ISR: Interrupt service routine that handles a specific interrupt.
- Interrupt vector: Table of ISR addresses indexed by interrupt number.
- DMA: Direct memory access: device moves data to/from memory without per-byte CPU work.
- NMI: Non-maskable interrupt that cannot be disabled.
- Synchronous: trap/exception (same instruction always triggers). Asynchronous: hardware interrupt (can occur between any two instructions).
Solved examples
Which of these must run in kernel mode: (a) read system clock, (b) disable interrupts, (c) execute a trap instruction, (d) set the timer register?
Identify privileged instructions
Formula Applied:—Approach note: Ask: could this let a user program take control of the machine? If yes, it is privileged.
Describe the sequence of events when a user program calls read(fd, buf, n).
Ordered steps of a system call
Formula Applied:—Approach note: Key words for full marks: trap, mode switch, system call table, parameter passing, return to user mode.
A user program executes a divide-by-zero. Is this a system call? What mechanism brings the OS in?
Classification
Formula Applied:—Approach note: System calls are intentional; exceptions/interrupts can be involuntary.
Name two advantages of a monolithic kernel and one disadvantage versus a microkernel.
Trade-offs
Formula Applied:—Approach note: Exams love: monolithic = speed; microkernel = isolation + IPC cost.
Real-world applications
Using OS Structures & System Calls in real projects
Linux/Windows internals, container isolation, device drivers, writing safe system software, and debugging syscall-heavy programs with tools like strace.
Common mistakes
❌ Myth: Every library function such as printf is a system call.
Why this is wrong: printf formats text in user space and only eventually calls write, which is the system call.
✅ Verified Truth: A system call is a controlled entry into the kernel via a trap; library functions may or may not use one.
⚠️ Exam Tip: Differentiate API/library call from system call in definitions.
❌ Myth: A microkernel is always faster because it is smaller.
Why this is wrong: Services outside the kernel communicate through message passing, which adds copying and context switches.
✅ Verified Truth: Microkernels trade some speed for reliability and modularity.
⚠️ Exam Tip: Quote the trade-off: reliability and security vs IPC overhead.
Revision notes
An operating system manages hardware and gives programs a safe, uniform interface. This chapter covers OS roles, the user/kernel split with dual-mode protection, system calls, monolithic vs microkernel designs, and how interrupts and traps transfer control into the kernel.
High-Yield Quick Revision Points
- OS = resource manager + abstraction + protection
- Mode bit: privileged instructions only in kernel mode
- System call: wrapper → trap → table dispatch → return
- Monolithic fast but fragile; microkernel safe but IPC overhead
- Interrupt = async (hardware); trap/exception = sync (instruction)
- Timer interrupt guarantees OS regains the CPU
Practice questions
Which instruction is NOT privileged?
A trap is best described as:
Which is a key advantage of a microkernel over a monolithic kernel?
The mechanism that lets the OS regain CPU control from a looping user program is: