Computer Science & Applications (Paper 2) (Code 87) · Unit 5 of 10

System Software & Operating Systems

ऑपरेटिंग सिस्टम

Unit overview: the topics below, with their summaries, are the syllabus for this unit. The comprehensive note further down covers every topic in full — explanations, definitions, worked examples, tables, exam points and practice questions — and the short revision note after it is only a quick recap. Standalone one-topic learning pages are not built yet — every topic on this page is covered in the notes and the practice questions below, and each topic card links to those sections.

Premium chapters for this unit

Processes, threads & scheduling → premium chapter · free preview · ~17 min · 4 practice questions

Memory management & virtual memory → premium chapter · free preview · ~17 min · 4 practice questions

Deadlock, file systems & I/O → premium chapter · free preview · ~16 min · 4 practice questions

Topics checklist — with weightage (platform estimate from past-question frequency, not an NTA guarantee)

Processes, threads & scheduling

High weightage

FCFS/SJF/RR, context switch, IPC.

Memory management & virtual memory

High weightage

Paging, segmentation, page replacement (FIFO/LRU/OPT).

Deadlock, file systems & I/O

Medium

Deadlock conditions, disk scheduling, file allocation.

Comprehensive unit note · ~20 min read

An operating system is the layer of system software that sits between the user, the application programs, and the hardware. It does two jobs at once: it makes the machine convenient to use, by hiding messy hardware details behind files, processes, and windows, and it manages resources efficiently, by deciding which program gets the CPU, how much memory each program may use, and in what order disk requests are served. Without it, every application would have to talk directly to the processor, the memory chips, and the disk controller, and two programs could easily corrupt each other's data. This unit studies the operating system from the inside. It begins with the process, the fundamental unit of execution, and asks how the system creates, schedules, suspends, and resumes processes, and how lighter-weight threads inside one process share work. It then turns to the classic coordination problem: when several processes run at once, how do they share data without race conditions, and how does the scheduler choose fairly between a short interactive job and a long batch job. Scheduling calculations recur throughout the unit. The second half of the unit deals with memory and storage. Virtual memory lets a program behave as if it had a large, private, contiguous address space even when physical memory is small and fragmented. Paging, page tables, and the translation lookaside buffer make that illusion fast, while page-replacement algorithms decide which page to evict when memory is full. Deadlock shows what happens when that sharing goes wrong in a circular way, and the Banker's algorithm shows how a system can refuse an unsafe request before the circle closes. Finally, file allocation, disk scheduling, and input-output cover storage and slow devices.

Learning objectives

  • Describe process states, the process control block, context switching, and the differences between processes and threads.
  • Compute waiting time and turnaround time for FCFS, SJF, SRTF, round robin, and priority scheduling from a Gantt chart.
  • Explain race conditions, critical sections, semaphores, and monitors, and recognise the classic synchronisation problems.
  • Explain paging, segmentation, page tables, TLB operation, thrashing, and page-replacement algorithms with fault counts.
  • Apply the deadlock conditions, resource-allocation graphs, and the Banker safety test to a given system state.
  • Compare file-allocation methods and compute total head movement for FCFS, SSTF, SCAN, and C-SCAN disk scheduling.
  • Explain interrupts, DMA, spooling, and buffering and why each exists.

Overview: what this unit covers

Think of this unit as three linked questions. First, who runs, and in what order: processes, threads, and CPU scheduling, plus the synchronisation rules that stop concurrent processes from corrupting shared data. Second, where does data live while a program runs: memory management and virtual memory, including paging, replacement, and thrashing. Third, what happens when sharing goes wrong or reaches slow hardware: deadlock, file systems, disk scheduling, and input-output. Learn the terms as one connected system.

Processes, threads & scheduling

A program is passive code stored on disk; a process is that program in execution, together with its program counter, registers, stack, data, and open files. A process moves through states: new, ready, running, waiting, and terminated. Ready waits only for the CPU; running holds it; waiting waits for an event; terminated has finished. The operating system records all of this in the process control block, or PCB, which holds the process identifier, state, program counter, CPU registers, scheduling information, memory information, accounting data, and input-output status. When the CPU switches from one process to another, it saves the old process state into its PCB and loads the new one, an operation called a context switch. Context switching is pure overhead.

A thread is a lighter unit of execution inside a process. Threads of one process share the code, data, and open files, but each has its own program counter, registers, and stack. Because threads share so much, creating a thread and switching between threads of the same process is cheaper than creating a process and switching between processes. Multithreading models describe how user threads map to kernel threads: many-to-one maps many user threads to one kernel thread, so one blocking system call blocks them all; one-to-one maps each user thread to a kernel thread, giving true parallelism at higher cost; and many-to-many multiplexes many user threads over a smaller or equal number of kernel threads.

CPU scheduling decides which ready process runs next. The criteria are CPU utilisation, throughput, turnaround time, waiting time, and response time. Turnaround time is completion time minus arrival time; waiting time is turnaround time minus burst time; response time is the time from arrival to first CPU use. Schedulers may be non-preemptive or preemptive. First-come first-served is simple and non-preemptive but suffers the convoy effect, where one long process delays many short ones behind it. Shortest-job-first chooses the smallest next burst and gives the minimum average waiting time among non-preemptive algorithms, but it can starve long processes and needs burst estimates. Shortest-remaining-time-first is its preemptive version. Round robin cycles processes through a fixed time quantum. Priority scheduling attaches a priority to each process and can starve low-priority processes unless aging gradually raises the priority of a process that has waited long. Multilevel feedback queues let a process move between queues based on its behaviour.

When processes share data, a race condition occurs if the final result depends on the order in which processes access shared data. The part of code that accesses shared data is the critical section. A correct solution must give mutual exclusion, so only one process is in its critical section at a time, progress, so no process outside the critical section blocks others, and bounded waiting, so no process waits forever to enter. A semaphore is an integer variable accessed only through two atomic operations: wait, which decrements the value and blocks the caller if it becomes negative, and signal, which increments the value and wakes a waiting process. A binary semaphore takes only values zero and one and works like a lock; a counting semaphore can take any non-negative value and tracks a pool of identical resources. A monitor is a higher-level construct: an abstract data type whose procedures are mutually exclusive by construction, with condition variables for waiting and signalling inside it. Classic problems include producer-consumer, readers-writers, and dining philosophers. Expect Gantt-chart arithmetic and questions on starvation and preemption.

Memory management & virtual memory

Every process sees logical addresses generated by the CPU, while the hardware works with physical addresses in real memory. The memory management unit translates logical addresses to physical ones, usually at run time, so a program can be loaded at different physical locations without being rewritten. In contiguous allocation, each process occupies one continuous block of memory. Fixed partitioning divides memory into fixed blocks, wasting space inside a block when a process is smaller, which is internal fragmentation. Variable partitioning gives each process exactly the block it requests, but leaves scattered holes that are individually too small, which is external fragmentation. Allocation strategies choose among holes: first-fit takes the first hole large enough, best-fit takes the smallest adequate hole, and worst-fit takes the largest hole. First-fit is usually fastest; best-fit can leave many tiny unusable fragments.

Paging removes external fragmentation by dividing logical memory into fixed-size pages and physical memory into frames of the same size. A page table maps each page number to a frame number, and a logical address splits into a page number and an offset within the page. A page table kept in memory would double memory accesses, so the translation lookaside buffer, or TLB, caches recent page-to-frame translations in fast associative memory. The effective access time combines these cases: if the hit ratio is h, memory access time is m, and the extra cost of a page-table lookup is folded in, the usual textbook form is effective access time equals h times the fast path plus (1 minus h) times the slow path. Multilevel page tables page the page table itself; an inverted page table keeps one entry per frame. Segmentation divides a program by logical meaning, such as code, data, stack, and heap, so each segment has a name, a base, and a limit, and addresses are checked against the segment limit. Many systems combine paging and segmentation.

Virtual memory goes further: it lets a program run even when only part of it is in physical memory. With demand paging, a page is loaded only when it is referenced. A reference to a page not in memory causes a page fault, and the system loads the page and restarts the instruction. If no frame is free, a victim page must be chosen for replacement. Page-replacement algorithms are judged by the number of page faults on a reference string. First-in first-out evicts the oldest loaded page and is simple but can evict a heavily used page, and it can show Belady's anomaly, where giving the process more frames increases the number of faults. Least recently used evicts the page unused for the longest time, on the principle that the recent past predicts the near future; it performs well but needs hardware support to track usage order. Optimal replacement evicts the page whose next use is farthest in the future, or never, and gives the fewest faults, but it requires knowledge of the future and so serves as a benchmark, not a practical algorithm. Thrashing is the collapse that follows when a process spends more time paging than executing: the degree of multiprogramming is too high, frames are too few, and the system services page faults instead of doing useful work. The working-set model keeps each process's recently referenced pages in memory. Expect fault counts, effective-access-time calculations, and fragmentation distinctions.

Deadlock, file systems & I/O

Deadlock is a state in which each process in a set waits for a resource held by another process in the set, so none can proceed. Four conditions must all hold simultaneously: mutual exclusion, meaning a resource is held by one process at a time; hold and wait, meaning a process holds resources while waiting for more; no preemption, meaning a resource can be released only voluntarily by its holder; and circular wait, meaning a cycle of processes each waiting for a resource held by the next. A resource-allocation graph makes this visible: processes are circles, resource types are squares with one dot per instance, an edge from a process to a resource is a request, and an edge from a resource to a process is an assignment. A cycle is necessary for deadlock; with one instance per resource type it is also sufficient.

Deadlock can be handled four ways. Prevention breaks at least one of the four conditions. Avoidance allows requests only when the resulting state is safe. The Banker's algorithm is the standard avoidance method: a state is safe if there is an order in which every process can finish using currently available resources plus the resources released by processes that finish earlier. A request is granted only if it leaves the state safe; otherwise the process waits. Detection and recovery lets deadlock occur, periodically checks for it, and then recovers by aborting a process or preempting a resource, accepting the cost of lost work. Ignoring deadlock, sometimes called the ostrich approach, is what many real systems do when deadlock is rare and prevention is expensive.

A file system must decide how a file's blocks are placed on disk. Contiguous allocation stores each file in consecutive blocks, giving fast sequential and direct access, but it suffers external fragmentation and makes growing a file hard. Linked allocation stores each block with a pointer to the next, so files can grow easily and no external fragmentation occurs, but direct access requires following pointers and a lost pointer loses the rest of the file. Indexed allocation keeps an index block holding pointers to all data blocks, giving direct access without external fragmentation, at the cost of the index block itself and a limit on file size unless multilevel indexing is used. Directories map names to file metadata and locations.

Disk scheduling orders requests to a moving head. FCFS serves in arrival order but can move the head far. Shortest-seek-time-first serves the nearest pending request and reduces total movement, but can starve distant requests. SCAN, the elevator algorithm, moves in one direction serving requests until the end of the disk, then reverses; C-SCAN moves in one direction only and jumps back to the start without serving on the return, giving more uniform waiting times. LOOK variants stop at the last request instead of the disk end.

Input-output completes the picture. Polling makes the CPU repeatedly check a device, wasting cycles. Interrupts let a device signal the CPU when it needs attention, so the CPU works on other tasks in between and handles the device only on the signal. Direct memory access goes further: a DMA controller transfers a whole block between device and memory without the CPU moving each byte, interrupting the CPU only when the block transfer finishes. Buffering holds data temporarily to smooth speed differences between producer and consumer, while spooling queues jobs for a slow device, classically a printer, so that several processes can write to a spool area on disk while only one job at a time actually reaches the device. Expect Banker sequences and disk-scheduling totals.

Key definitions

  • Process: A program in execution, including its code, data, stack, registers, program counter, and open files.
  • Process control block (PCB): The operating system record for a process, holding its identifier, state, program counter, registers, scheduling and memory information, and input-output status.
  • Context switch: Saving the state of the running process into its PCB and loading the state of another process so the CPU can resume it later.
  • Thread: A unit of execution inside a process that shares code, data, and files with sibling threads but has its own program counter, registers, and stack.
  • Turnaround time: Completion time minus arrival time for a process.
  • Waiting time: Turnaround time minus burst time, that is, the total time a process spends in the ready queue.
  • Critical section: The part of a program that accesses shared data and must be executed by at most one process at a time.
  • Semaphore: An integer variable accessed only by atomic wait and signal operations, used for synchronisation and for counting available resources.
  • Monitor: An abstract data type whose procedures are mutually exclusive by construction, with condition variables for waiting inside the monitor.
  • Page: A fixed-size block of logical memory; physical memory is divided into frames of the same size.
  • Page fault: An event that occurs when a referenced page is not in physical memory and must be loaded from disk.
  • TLB: A small, fast associative cache of recent page-table translations that speeds up address translation.
  • Thrashing: A state in which a system spends more time servicing page faults than executing processes, usually because too many processes share too few frames.
  • Deadlock: A state in which each process in a set waits for a resource held by another process in the set, so no process can proceed.
  • Safe state: A system state in which there is an order allowing every process to finish, so granting a request keeps deadlock avoidable.
  • Spooling: Queuing jobs for a slow device in a spool area on disk so several processes can share the device without waiting for it directly.
  • DMA: Direct memory access: a controller transfers a block between device and memory without the CPU moving each byte.

Formulas

  • Turnaround time = Completion time - Arrival time
  • Waiting time = Turnaround time - Burst time
  • Average waiting time = Sum of waiting times / Number of processes
  • Average turnaround time = Sum of turnaround times / Number of processes
  • Effective access time = (Hit ratio x Fast access time) + ((1 - Hit ratio) x Slow access time), where the slow path includes the page-table lookup
  • Effective access time with page faults = (1 - p) x Memory access time + p x Page-fault service time, where p is the page-fault probability

Worked examples

Example 1: Three processes arrive as follows: P1 arrives at time 0 with burst 24, P2 arrives at time 1 with burst 3, and P3 arrives at time 2 with burst 3. Draw the first-come first-served Gantt chart and find the average waiting time and average turnaround time.

FCFS serves in arrival order, so the Gantt chart is P1 from 0 to 24, P2 from 24 to 27, and P3 from 27 to 30. Completion times are P1 24, P2 27, P3 30. Turnaround times are completion minus arrival: P1 24 - 0 = 24, P2 27 - 1 = 26, P3 30 - 2 = 28. Average turnaround time is (24 + 26 + 28) / 3 = 78 / 3 = 26. Waiting times are turnaround minus burst: P1 24 - 24 = 0, P2 26 - 3 = 23, P3 28 - 3 = 25. Average waiting time is (0 + 23 + 25) / 3 = 48 / 3 = 16. The long P1 delays both short processes, which is the convoy effect.

Example 2: For the reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 with 3 frames, find the number of page faults under FIFO, LRU, and optimal replacement.

FIFO evicts the oldest page and gives 15 faults. Counting faults across the string gives 15 in total. LRU evicts the least recently used page and gives 12 faults, because pages such as 0 and 2 that are referenced repeatedly stay in memory longer than under FIFO. Optimal replacement evicts the page whose next use is farthest in the future and gives 9 faults, the fewest possible for this string, but it can only be computed because the whole string is known in advance. The ordering FIFO 15, LRU 12, optimal 9 is the standard result for this classic string.

Example 3: A system has 5 processes and 3 resource types with total instances A 10, B 5, C 7. Allocation is P0 (0,1,0), P1 (2,0,0), P2 (3,0,2), P3 (2,1,1), P4 (0,0,2). Maximum demand is P0 (7,5,3), P1 (3,2,2), P2 (9,0,2), P3 (2,2,2), P4 (4,3,3). Is the state safe, and if so give a safe sequence.

First compute Need as Maximum minus Allocation: P0 (7,4,3), P1 (1,2,2), P2 (6,0,0), P3 (0,1,1), P4 (4,3,1). Total allocated is A 7, B 2, C 5, so Available is (10 - 7, 5 - 2, 7 - 5) = (3,3,2). Check safety with Work starting at Available. P1 need (1,2,2) fits in (3,3,2), so P1 finishes and Work becomes (3 + 2, 3 + 0, 2 + 0) = (5,3,2). P3 need (0,1,1) fits, so Work becomes (7,4,3). P4 need (4,3,1) fits, so Work becomes (7,4,5). P0 need (7,4,3) fits, so Work becomes (7,5,5). P2 need (6,0,0) fits, so Work becomes (10,5,7). Every process finishes, so the state is safe with safe sequence P1, P3, P4, P0, P2.

Example 4: A disk queue holds 98, 183, 37, 122, 14, 124, 65, 67 in that order, with the head at cylinder 53. Compute total head movement under FCFS and under SSTF.

FCFS follows arrival order: 53 to 98 is 45, to 183 is 85 (total 130), to 37 is 146 (total 276), to 122 is 85 (total 361), to 14 is 108 (total 469), to 124 is 110 (total 579), to 65 is 59 (total 638), to 67 is 2 (total 640). Total FCFS head movement is 640 cylinders. SSTF always takes the nearest pending request: from 53 to 65 is 12, to 67 is 2 (total 14), to 37 is 30 (total 44), to 14 is 23 (total 67), to 98 is 84 (total 151), to 122 is 24 (total 175), to 124 is 2 (total 177), to 183 is 59 (total 236). Total SSTF head movement is 236 cylinders, far less than FCFS, but a request far from the head could be delayed repeatedly if new near requests keep arriving.

CPU scheduling algorithms compared

AlgorithmPreemptiveMain drawback
FCFSNoConvoy effect: one long job delays short jobs
SJFNoStarvation of long jobs; burst times must be estimated
SRTFYesStarvation of long jobs; needs remaining-time estimates
Round robinYesSmall quantum raises context-switch overhead
PriorityUsually yesStarvation of low-priority jobs unless aging is used

Page-replacement algorithms compared

AlgorithmVictim chosenFaults on the classic 3-frame string
FIFOOldest loaded page15
LRULeast recently used page12
OptimalPage used farthest in the future9

File-allocation methods compared

MethodStrengthWeakness
ContiguousFast sequential and direct accessExternal fragmentation; growing a file is hard
LinkedNo external fragmentation; easy growthDirect access is slow; a lost pointer loses the tail
IndexedDirect access without external fragmentationIndex block overhead; file size limited by index size

Diagrams (described)

Process state diagram: New -> (admitted) -> Ready -> (dispatched) -> Running -> (exit) -> Terminated; Running -> (interrupt) -> Ready; Running -> (I/O or event wait) -> Waiting -> (event completion) -> Ready.

Address translation flow: Logical address (page number, offset) -> TLB lookup; on a hit, frame number is read from the TLB; on a miss, the page table in memory is consulted; physical address = frame number combined with the offset.

Banker safety check flow: compute Need = Maximum - Allocation; set Work = Available; repeatedly find an unfinished process whose Need fits in Work, mark it finished, and add its Allocation to Work; if all processes finish, the state is safe.

SCAN elevator flow: head moves in one direction serving requests in order until the end, then reverses direction and serves requests on the way back; C-SCAN instead jumps back to the start and serves only in the forward direction.

Exam points

  • SJF gives minimum average waiting time among non-preemptive algorithms; SRTF is its preemptive form.
  • Round robin with a very large quantum behaves like FCFS; a very small quantum raises context-switch overhead.
  • Aging prevents starvation in priority scheduling by gradually raising the priority of a waiting process.
  • Belady anomaly: FIFO can fault more often when more frames are given; LRU and optimal do not show it.
  • Optimal page replacement gives the fewest faults but needs future knowledge, so it is a benchmark only.
  • Internal fragmentation is wasted space inside an allocated block; external fragmentation is scattered free holes too small to use.
  • A cycle in a resource-allocation graph proves deadlock only when each resource type has a single instance.
  • The Banker algorithm grants a request only when the resulting state is safe.
  • DMA transfers a whole block without the CPU moving each byte; the CPU is interrupted only when the transfer finishes.
  • Spooling queues jobs on disk for a device that serves one job at a time; buffering smooths speed differences between producer and consumer.

Common mistakes

  • Mistake: saying a process and a program are the same. Correction: a program is passive code on disk; a process is that program in execution with its own state, registers, and resources.
  • Mistake: computing waiting time as completion minus arrival. Correction: that is turnaround time; waiting time is turnaround time minus burst time.
  • Mistake: calling SRTF non-preemptive. Correction: SRTF preempts the running process when a new process arrives with a shorter remaining time.
  • Mistake: saying paging causes external fragmentation. Correction: paging removes external fragmentation; the waste inside the last page of a process is internal fragmentation.
  • Mistake: treating a resource-allocation cycle as proof of deadlock with multiple resource instances. Correction: with multiple instances a cycle only means deadlock is possible; the state must be checked further.
  • Mistake: saying optimal replacement is used in practice. Correction: it needs future reference knowledge, so it is a benchmark for comparing FIFO and LRU.
  • Mistake: confusing spooling with buffering. Correction: spooling queues whole jobs on disk for a single-job device; buffering holds data temporarily to match producer and consumer speeds.
  • Mistake: saying DMA removes interrupts entirely. Correction: DMA removes per-byte CPU work, but the CPU is still interrupted once when the block transfer completes.

Practice questions from this note (original practice — not official PYQs)

Checking login…

Quick revision: Processes run, threads share, schedulers choose. Remember the state cycle new, ready, running, waiting, terminated, and the PCB as the saved state that makes a context switch possible. For scheduling, compute turnaround as completion minus arrival and waiting as turnaround minus burst, then average; SJF minimises average waiting among non-preemptive algorithms, SRTF preempts it, round robin depends on the quantum, and aging cures priority starvation. For synchronisation, hold three requirements together: mutual exclusion, progress, bounded waiting, with semaphores for counting and monitors for built-in exclusion. For memory, paging maps pages to frames through a page table cached by the TLB, demand paging faults on missing pages, FIFO faults most, LRU less, optimal least, and thrashing means paging has replaced execution. For deadlock, all four conditions must hold, a single-instance cycle proves it, and the Banker test admits only safe states. For disks, FCFS is fair but travels far, SSTF travels least but can starve, SCAN sweeps and reverses, C-SCAN sweeps one way only. DMA moves blocks, spooling queues jobs, buffering smooths speeds.

Unit revision note (quick recap)

An OS is a resource manager and an illusion-maker: many programs share one CPU and memory, each believing it owns the machine.

Learning objectives

  • Compare scheduling algorithms
  • Explain paging and page replacement
  • Explain deadlock and file systems

Key concepts

  • Round Robin: Preemptive, time-sliced scheduling: each process gets a fixed quantum in turn.
  • Paging: Fixed-size pages/frames; eliminates external fragmentation, may leave internal fragmentation.
  • FIFO / LRU / OPT: Page replacement: oldest, least recently used, farthest future use (optimal benchmark).
  • Deadlock conditions: Mutual exclusion, hold-and-wait, no preemption, circular wait — all four are needed.

Formulas

  • Average waiting time depends on the schedule; RR quantum too small → many context switches

Worked examples

  • Pages 1,2,3,4,1,2,5 with 3 frames under FIFO: 7 faults (worked in the question bank).

Exam points

  • SJF minimises average waiting time but can starve long jobs.
  • Belady’s anomaly: more frames can increase FIFO faults.

Common mistakes

  • Confusing internal fragmentation (wasted space inside a frame/page) with external fragmentation (free holes too small).

Quick revision: Processes/threads, scheduling, synchronisation, memory, virtual memory, deadlock, files, disk scheduling.

Practice questions from the whole unit bank (33 in the bank)

This unit's practice bank — the note above has its own smaller practice set drawn from the same bank, so a question can appear in both lists. The list below shows the free sample or the full bank depending on your plan.

Checking login…

Related tests

Unit test for this unit (33 bank questions, 40 min) · Full Mock — CS Paper 2 (100 questions) · Combined 150-question mock (180 min). All +2 per correct, no negative marking.

Revision summary

Processes/threads, scheduling, synchronisation, memory, virtual memory, deadlock, files, disk scheduling.

After revising, take the unit test above, then check your unit-wise report on the Dashboard to find weak topics.