Operating System
An operating system is the software layer between user applications and computer hardware. Its primary responsibilities are process management, memory mana...
Core Operating System Concepts and Functions
An operating system is the software layer between user applications and computer hardware. Its primary responsibilities are process management, memory management, file system management, and device I/O coordination. Understanding each responsibility deeply — not just definitionally — is essential for both GATE and real-world systems programming.
Process management encompasses the creation, scheduling, synchronization, and termination of processes. A process is a program in execution, consisting of a code segment, data segment, heap, and stack, along with OS-managed state such as the program counter, register values, and open file descriptors encapsulated in the Process Control Block (PCB). The OS scheduler determines which process runs on the CPU at any moment, balancing throughput, fairness, and response time goals.
Memory management involves allocating physical memory to processes, protecting each process's address space from others, and creating the illusion of more memory than physically exists through virtual memory. Techniques include contiguous allocation (base and limit registers), segmentation (logical segments with independent sizes), and paging (fixed-size pages mapped to physical frames). Modern OSes use segmented paging, combining both.
The file system organizes persistent data into named files and directories. The OS manages a hierarchical namespace, controls access through permissions, and translates file offsets to disk block addresses using structures like i-nodes (Unix) or FAT entries (Windows). Understanding how the OS locates a block of a large file (direct blocks, single indirect, double indirect pointers) is a common GATE topic.
Device management abstracts hardware diversity through device drivers. The OS provides a uniform interface (open, read, write, close) regardless of whether the underlying device is a disk, network card, or terminal. Buffering, caching, and spooling are techniques the OS uses to smooth out speed mismatches between processes and devices. Buffering holds data temporarily in memory; spooling queues output for a slow device like a printer so the process can proceed without waiting.
Process Scheduling Algorithms Explained
CPU scheduling algorithms determine the order in which ready processes receive CPU time. Each algorithm has distinct performance characteristics under different workload patterns, and GATE expects you to compute average waiting time, average turnaround time, and sometimes average response time for each.
First Come First Served (FCFS) processes jobs in the order they arrive. It is non-preemptive, simple to implement, but suffers from the convoy effect: a long job at the front of the queue delays all shorter jobs behind it, leading to poor average waiting time when job lengths vary widely.
Shortest Job First (SJF) selects the process with the shortest next CPU burst. Non-preemptive SJF waits until the CPU is free before making a scheduling decision. Preemptive SJF (also called Shortest Remaining Time First, SRTF) can preempt a running process if a new arrival has a shorter burst. SJF is provably optimal for minimizing average waiting time among non-preemptive algorithms, and SRTF is optimal overall — but both require knowing burst length in advance, which is typically estimated using exponential averaging.
Round Robin (RR) assigns each process a fixed time quantum and cycles through the ready queue. It is designed for time-sharing systems where responsiveness is more important than throughput. A small quantum improves response time but increases context-switch overhead. A large quantum degenerates toward FCFS. GATE often asks you to compute average waiting time for RR with a given quantum.
Priority scheduling assigns a numeric priority to each process; the scheduler always runs the highest-priority ready process. Starvation — where low-priority processes never run — is a serious problem. Aging solves this by gradually increasing the priority of waiting processes. Multilevel feedback queues combine multiple priority queues with aging, I/O-bound boosting, and dynamic demotion of CPU-bound processes.
To compute average waiting time: for each process, waiting time equals completion time minus arrival time minus burst time. Sum all waiting times and divide by the number of processes.
Deadlock: Detection, Prevention, and Avoidance
Deadlock occurs when a set of processes are each waiting for a resource held by another process in the set, creating a circular dependency that no process can break unilaterally. Formally, deadlock requires all four Coffman conditions to hold simultaneously: mutual exclusion, hold and wait, no preemption, and circular wait.
Mutual exclusion means a resource can be used by only one process at a time — inherent to non-sharable resources like printers. Hold and wait means a process holds at least one resource while waiting to acquire additional ones. No preemption means resources cannot be forcibly taken from a process; they must be released voluntarily. Circular wait means there exists a cycle in the resource allocation graph where each process waits for a resource held by the next.
Deadlock prevention eliminates at least one Coffman condition. To prevent hold and wait, require processes to request all resources before execution begins — wasteful but deadlock-free. To allow preemption, take resources from a waiting process if needed — feasible for resources whose state can be saved and restored, like CPU registers. To prevent circular wait, impose a global ordering on resource types and require processes to request resources only in ascending order.
Deadlock avoidance uses additional information about future resource needs to ensure the system never enters an unsafe state. The Banker's Algorithm is the canonical example. It maintains the maximum demand of each process, current allocation, and remaining available resources. Before granting a request, it checks whether a safe sequence exists — an ordering of all processes such that each can complete using currently available plus eventually released resources. If no safe sequence exists after granting the request, the request is denied.
Deadlock detection allows deadlock to occur but periodically runs a detection algorithm (cycle detection in the resource allocation graph) and recovers by killing processes or preempting resources. GATE most frequently tests the Banker's Algorithm, requiring you to determine whether a given state is safe and what requests can be granted.