If one subject explains what your servers are doing, it is Operating Systems. Load average, OOM kills, zombie processes, file descriptors, container limits and swap are all in these five units. This article revisits the JNTUK course with the Linux behaviour of each idea.
Unit 1: Introduction, system calls and processes
What an OS does
An operating system manages hardware for programs: it allocates the CPU, memory, storage and devices, and offers a clean interface, protection and fair sharing. Main parts: the kernel, system libraries and tools. The CPU runs in two modes: user mode (restricted) and kernel mode (privileged).
| OS kernel design | Idea |
|---|---|
| Monolithic | Everything in one kernel (Linux) |
| Microkernel | Minimal kernel, services run as user processes |
| Layered, hybrid | Mixtures (Windows, macOS) |
A system call is the controlled way a program asks the kernel for a service (open, read, write, fork, exec, mmap); it traps into kernel mode. An interrupt signals an event from hardware. strace shows a program’s system calls.
Processes
A process is a program in execution, with its own memory space: code, data, heap, stack, plus registers and open files. The process control block (PCB) stores its state.
| State | Meaning |
|---|---|
| New | Being created |
| Ready | Waiting for the CPU |
| Running | Executing |
| Waiting (blocked) | Waiting for I/O or an event |
| Terminated | Finished |
A context switch saves one process’s state and loads another’s; it is pure overhead. In Linux, fork() creates a copy of the process (using copy-on-write), exec() replaces its program, and a parent must wait() for a child; an unreaped child becomes a zombie.
Inter-process communication (IPC)
Pipes, message queues, shared memory, sockets and signals. Shared memory is the fastest; message passing is simpler and safer.
Today: a container is a process with isolated views (namespaces) and limits (cgroups); it is not a virtual machine.
ps,topandstraceare everyday tools, and PID 1 in a container must reap zombie children.
Unit 2: Threads and CPU scheduling
Threads
A thread is a unit of execution inside a process; threads share the code, heap and open files but have their own stack and registers. They are lighter than processes and communicate through shared memory, which is also what makes synchronization necessary. Thread models: user-level, kernel-level, and many-to-many mappings.
Scheduling
The scheduler picks which ready process runs next. Goals: high CPU utilization and throughput, low turnaround, waiting and response time, and fairness.
| Algorithm | Idea | Notes |
|---|---|---|
| FCFS | First come, first served | Simple; the convoy effect (short jobs wait behind a long one) |
| SJF | Shortest job first | Minimises average waiting time; needs burst-length knowledge; can starve long jobs |
| SRTF | Preemptive SJF | Shortest remaining time first |
| Priority | Highest priority first | Starvation is fixed by aging |
| Round robin | Each process gets a time quantum in turn | Good response time; the quantum size matters |
| Multilevel queue / feedback queue | Several queues, processes can move between them | Used in real systems |
Scheduling can be preemptive (the OS can take the CPU away) or non-preemptive. A worked example: processes with burst times 6, 8 and 3 under FCFS wait 0, 6 and 14, an average of 6.7; under SJF (order 3, 6, 8) they wait 0, 3 and 9, an average of 4.
Real-time scheduling uses rate-monotonic and earliest-deadline-first. Linux uses the Completely Fair Scheduler (CFS), which gives each task a fair share of CPU time, and newer schedulers in recent kernels.
Today: “load average” counts runnable (and waiting) tasks.
nicechanges priority, and a Kubernetes CPU request sets a weight in the scheduler while a CPU limit causes throttling. High context-switch counts hint at too many threads.
Unit 3: Synchronization and deadlocks
The critical-section problem
When threads share data, a race condition occurs if the result depends on timing. The critical section is the code that touches shared data; a solution must give mutual exclusion, progress and bounded waiting.
| Tool | Description |
|---|---|
| Peterson’s solution | Software solution for two processes |
| Test-and-set / compare-and-swap | Atomic hardware instructions |
| Mutex lock | One owner at a time |
| Semaphore | A counter with atomic wait (P) and signal (V); binary or counting |
| Monitor | A language construct that bundles data, locks and condition variables |
Classical problems
Producer-consumer (bounded buffer), readers-writers, dining philosophers. They show problems such as starvation and deadlock.
Deadlock
A deadlock is a set of processes each waiting for a resource held by another. It needs four conditions together (Coffman conditions):
| Condition | Meaning |
|---|---|
| Mutual exclusion | A resource is used by one at a time |
| Hold and wait | A process holds resources while waiting for more |
| No preemption | Resources cannot be taken away |
| Circular wait | A cycle of waiting processes |
| Strategy | How |
|---|---|
| Prevention | Break one of the four conditions (for example, order locks globally to avoid circular wait) |
| Avoidance | The Banker’s algorithm grants a request only if the system stays in a safe state |
| Detection and recovery | Find cycles in the wait-for graph, then kill or roll back a process |
| Ignore | The “ostrich” approach, used by most general-purpose systems |
Today: databases, distributed locks and thread pools deadlock in just this way, and “always acquire locks in the same order” is the standard rule. Java thread dumps show deadlocks, and databases pick a victim and roll back. Lock contention is a common reason an app does not scale with more CPUs.
Unit 4: Memory management
Basic schemes
| Scheme | Idea | Drawback |
|---|---|---|
| Contiguous allocation | One block per process | External fragmentation; first-fit, best-fit, worst-fit |
| Paging | Split memory into fixed frames and programs into pages | Internal fragmentation in the last page |
| Segmentation | Split by logical parts (code, stack, data) | External fragmentation |
With paging, a logical address = page number + offset. The page table maps pages to frames, and the TLB caches recent translations. The effective access time = hit ratio × (TLB + memory) + miss ratio × (TLB + 2 × memory) for a single-level table. Large address spaces use multilevel and inverted page tables.
Virtual memory
Virtual memory lets a program use more memory than is physically present by keeping only the active pages in RAM and the rest on disk. A page fault occurs when a needed page is not in memory; the OS loads it (demand paging).
| Page replacement | Rule |
|---|---|
| FIFO | Replace the oldest page (can show Belady’s anomaly: more frames, more faults) |
| Optimal | Replace the page used farthest in the future (a benchmark, not implementable) |
| LRU | Replace the least recently used |
| Clock (second chance) | A practical approximation of LRU |
Thrashing happens when a system spends more time paging than running; the working set model and page-fault frequency control it. Copy-on-write and memory-mapped files are further tricks.
Today: swap, page cache and the OOM killer are this unit.
free -mandvmstatshow it, and a pod that exceeds its memory limit is killed (OOMKilled), whereas CPU is only throttled. Overcommitting memory, huge pages and “the page cache uses all free RAM, that’s fine” are all everyday questions.
Unit 5: Storage, file systems and I/O
File systems
A file has attributes (name, size, permissions, timestamps). Directories form a tree (with links in Unix). Operations: create, open, read, write, seek, delete.
| Allocation method | Idea | Trade-off |
|---|---|---|
| Contiguous | Consecutive blocks | Fast, but fragmentation |
| Linked | Each block points to the next | No external fragmentation, slow random access (FAT table improves this) |
| Indexed | An index block lists all the blocks | Supports direct access; Unix inodes use direct, indirect and double-indirect pointers |
An inode stores metadata and block pointers (not the name); the directory maps names to inodes. A hard link is another name for the same inode; a symbolic link is a file holding a path. Free-space management uses bitmaps or lists. Journaling file systems (ext4, XFS) log changes first, so they recover quickly after a crash. Access control uses permissions (rwx for user, group, other) and ACLs.
Disks and I/O
- Disk scheduling: FCFS, SSTF, SCAN (elevator), C-SCAN, LOOK reduce head movement on spinning disks; SSDs have no seek time, so simple schedulers are used.
- RAID: RAID 0 (striping, speed), 1 (mirroring), 5 (striping with parity), 6 (double parity), 10.
- I/O methods: polling, interrupt-driven and DMA; buffering, caching and spooling; device drivers.
Protection and security
Domains and access matrices, authentication (passwords, keys, multi-factor), encryption, and threats such as viruses, buffer overflows and privilege escalation.
Today:
df -ishowing “out of inodes” while disk space remains, and a full disk caused by deleted-but-open files, are classic production issues. Persistent volumes in Kubernetes are block or file storage with a file system on top. Cloud volumes (EBS) use RAID-like replication behind the scenes, and overlay file systems are how container image layers work.
One-minute recap
| Unit | Key idea | You meet it in |
|---|---|---|
| 1. Processes | PCB, states, system calls, fork and exec, IPC |
Containers, zombies, strace |
| 2. Threads and scheduling | FCFS, SJF, round robin, CFS | Load average, CPU requests and throttling |
| 3. Synchronization and deadlock | Mutex, semaphores, Coffman conditions, Banker’s | Lock contention, DB deadlocks |
| 4. Memory | Paging, TLB, page replacement, thrashing | Swap, OOM kills, memory limits |
| 5. Files and I/O | Inodes, journaling, disk scheduling, RAID | df -i, persistent volumes, overlay file systems |
Next in Engineering Revisited: Web Technologies.
Written by Claude, Anthropic’s AI assistant, as part of Engineering Revisited, a quick refresher of the B.Tech subjects one at a time.