Operating Systems

Table of Contents

  1. Operating System Overview
  2. Process Management
  3. Process Scheduling
  4. Threads
  5. Inter-Process Communication
  6. Process Synchronization
  7. Deadlock
  8. Memory Management
  9. Virtual Memory
  10. Disk Scheduling
  11. File Systems
  12. I/O Systems
  13. Linux/Windows OS Basics

Operating System Overview

An operating system is system software that manages computer hardware, software resources, and provides common services for computer programs.

OS Functions

  1. Process Management: Creation, scheduling, termination of processes
  2. Memory Management: Allocation and deallocation of memory
  3. File System Management: Creating, deleting, accessing files
  4. I/O System Management: Managing input/output devices
  5. Security and Access Control: User authentication, file permissions
  6. Network Management: Managing network connections
  7. User Interface: CLI, GUI, shell

Types of Operating Systems

Type Description Example
Batch OS Jobs grouped and executed without user interaction Early payroll systems
Time-Sharing/Multitasking Multiple users share CPU time UNIX, Linux
Real-Time OS (RTOS) Guaranteed response within strict time limits VxWorks, QNX
Distributed OS Multiple computers work as single system Amoeba, LOCUS
Network OS Server-based, manages network resources Novell NetWare
Mobile OS Designed for mobile devices Android, iOS

Real-Time OS Types

Kernel Types

Type Description Pros Cons
Monolithic All OS services in kernel space Fast (no context switching) Large, less reliable
Microkernel Minimal services in kernel; rest in user space Modular, reliable Slower (message passing)
Hybrid Combination of both Balanced Complex
Exokernel Minimal abstractions; apps manage hardware directly Maximum performance Complex for developers

Examples: Linux = Monolithic, Windows NT = Hybrid, QNX = Microkernel


Process Management

Program vs Process

Process States

State Description
New Process is being created
Ready Process is waiting to be assigned to CPU
Running Instructions are being executed
Waiting/Blocked Process is waiting for an event (I/O completion)
Terminated Process has finished execution

State Transitions

New  Ready (admitted)
Ready  Running (scheduler dispatch)
Running  Ready (interrupt / time slice expired)
Running  Waiting (I/O request / event wait)
Waiting  Ready (I/O completion / event occurred)
Running  Terminated (exit)

Process Control Block (PCB)

Each process has a PCB containing:
- Process State: Current state (ready, running, waiting, etc.)
- Process ID (PID): Unique identifier
- Program Counter: Address of next instruction to execute
- CPU Registers: All processor registers (accumulator, index, stack pointer)
- CPU Scheduling Info: Priority, scheduling queue pointers
- Memory Management Info: Page tables, segment tables, limits
- I/O Status Info: List of open files, allocated devices
- Accounting Info: CPU time used, time limits, account numbers

Context Switching

When CPU switches from one process to another:
1. Save state of old process into its PCB
2. Load state of new process from its PCB
3. Update memory management data structures

Context switch time is pure overhead — CPU does no useful work during the switch.


Process Scheduling

Scheduling Criteria

Metric Definition
CPU Utilization Keep CPU as busy as possible (ideally 100%)
Throughput Number of processes completed per unit time
Turnaround Time Total time from submission to completion
Waiting Time Time spent in ready queue
Response Time Time from submission to first response

CPU and I/O Bursts

Process execution alternates between CPU bursts (computation) and I/O bursts (waiting for input/output). CPU burst duration determines scheduling behavior.

Scheduling Algorithms

First Come First Served (FCFS)

Gantt: | P1 (0-24) | P2 (24-27) | P3 (27-30) |
- Turnaround: P1=24, P2=27, P3=30 → Avg = 27
- Waiting: P1=0, P2=24, P3=27 → Avg = 17

Shortest Job First (SJF)

Shortest Remaining Time First (SRTF)

Round Robin (RR)

Priority Scheduling

Multilevel Queue Scheduling

Multilevel Feedback Queue

Scheduling Algorithm Comparison

Algorithm Type Avg Wait Time Starvation Best For
FCFS Non-preemptive Can be high No Batch systems
SJF Non-preemptive Minimum Yes Known burst times
SRTF Preemptive Very low Yes Mixed workloads
RR Preemptive Moderate No Time-sharing
Priority Both Varies Yes Real-time systems
MLQ Both Varies Possible Mixed process types
MLFQ Both Flexible Rarely General-purpose

Threads

A thread is a lightweight process — the basic unit of CPU utilization.

Process vs Thread

Feature Process Thread
Memory Separate address space Shares address space with process
Communication IPC required (pipes, message queues) Direct memory access
Creation Slow (separate resources) Fast (shares resources)
Switching Heavy context switch Lightweight
Isolation Independent Not isolated (one thread crash affects all)
PCB One per process One TCB (Thread Control Block) per thread

Thread Types

Type Description Advantage Disadvantage
User Threads Managed by user-level library (no kernel support) Fast switching, no kernel mode One blocking call blocks all threads
Kernel Threads Managed by OS kernel True parallelism, blocking handled per thread Slower (kernel mode transitions)
Hybrid User threads mapped to kernel threads Best of both Complex

Threading Models

Model Description
Many-to-One Many user threads → 1 kernel thread (e.g., early GNU Portable Threads)
One-to-One Each user thread → 1 kernel thread (e.g., Linux, Windows — most common)
Many-to-Many Many user threads → many kernel threads (e.g., Solaris, Windows Fibers)

Thread Pools


Inter-Process Communication

Shared Memory

Message Passing

Other IPC Mechanisms

Mechanism Type Description
Pipes Message passing Unidirectional; between parent-child (unnamed pipe) or any process (named pipe/FIFO)
Message Queues Message passing Structured messages in queue; supports priorities
Sockets Message passing Network communication; can be used locally (Unix domain sockets)
Shared Memory Shared memory Fastest; requires synchronization
Signals Event notification Asynchronous notification (e.g., SIGKILL, SIGINT)
Semaphores Synchronization Integer variable for signaling between processes

Process Synchronization

Critical Section Problem

A critical section is a code segment that accesses shared variables. Only one process should execute it at a time.

Requirements for Solution:
1. Mutual Exclusion: Only one process in critical section
2. Progress: If no process is in CS, selection of next cannot be postponed
3. Bounded Waiting: Limit on how many times other processes can enter CS after a request

Solutions

Mutex (Mutual Exclusion Lock)

Semaphores

Types:
| Type | Description |
|------|-------------|
| Binary Semaphore (Mutex) | Values: 0 or 1; used for mutual exclusion |
| Counting Semaphore | Values: 0 to n; used for resource counting |

Semaphore with No Busy Waiting:
- Each semaphore has a waiting queue
- wait(): if S < 0, block process and add to queue; else S--
- signal(): if queue not empty, wake a process; else S++

Monitors

Classical Synchronization Problems

Producer-Consumer Problem

Reader-Writers Problem

Writer: wait(rw_mutex); WRITE; signal(rw_mutex);
```

Dining Philosophers Problem


Deadlock

Necessary Conditions (ALL must hold simultaneously)

  1. Mutual Exclusion: At least one resource held in non-sharable mode
  2. Hold and Wait: Process holds at least one resource and waits for others
  3. No Preemption: Resources cannot be forcibly taken
  4. Circular Wait: Set of processes {P₁, P₂, ..., Pₙ} where P₁ waits for P₂, P₂ waits for P₃, ..., Pₙ waits for P₁

Resource Allocation Graph

Deadlock Handling Strategies

Deadlock Prevention (Break one of 4 conditions)

Condition Prevention
Mutual Exclusion Make resources sharable (not always possible)
Hold and Wait Request all resources at once, or release all before requesting new
No Preemption If request denied, release all held resources
Circular Wait Impose ordering on resource types; request in increasing order

Deadlock Avoidance

Banker's Algorithm:
- Data Structures:
- Available[m]: Available resources of each type
- Max[n][m]: Maximum demand of each process
- Allocation[n][m]: Currently allocated resources
- Need[n][m] = Max - Allocation

Deadlock Detection

Deadlock Recovery

Method Description
Process Termination Abort all deadlocked processes, or one at a time
Resource Preemption Take resources from deadlocked processes; roll back
Victim Selection Choose process with minimum cost (least work, lowest priority)

Memory Management

Memory Allocation Strategies

Strategy Description Problem
First Fit Allocate first hole big enough Fast, may fragment
Best Fit Allocate smallest sufficient hole Lowers fragmentation but many tiny holes
Worst Fit Allocate largest hole Leaves larger fragments

Fragmentation

Paging

Multi-Level Paging:
- Page table itself is paginated (too large to store contiguously)
- Two-Level: Outer page table → inner page table → frame
- Reduces memory needed for page table storage

Inverted Page Table:
- One entry per physical frame (instead of per page)
- Reduces page table size but increases lookup time

Segmentation

Segmentation with Paging


Virtual Memory

Virtual memory allows execution of processes that are not completely in memory (separates logical from physical memory).

Demand Paging

Page Replacement Algorithms

FIFO (First In First Out)

Optimal (OPT/Bélády's)

LRU (Least Recently Used)

LRU Approximation Algorithms

Algorithm Description
Reference Bit Each page has bit; set when referenced; periodically cleared
Second Chance (Clock) FIFO with reference bit; skip pages with bit=1 (give second chance)
Enhanced Second Chance Combines reference bit + dirty bit; prefer replacing not-referenced, clean pages
NFU (Not Frequently Used) Software counter incremented; replace lowest counter

Page Replacement Comparison

Algorithm Page Faults Implementation
FIFO High Simple queue
Optimal Minimum Theoretical only
LRU Near-optimal Counters or stack
LRU Approx Good Reference bits

Thrashing

Working Set: Set of pages referenced in last Δ time units. OS ensures working set is in memory before process runs.


Disk Scheduling

Disk Access Time

Access Time = Seek Time + Rotational Latency + Transfer Time

Disk Scheduling Algorithms

FCFS (First Come First Served)

SSTF (Shortest Seek Time First)

SCAN (Elevator Algorithm)

C-SCAN (Circular SCAN)

LOOK

C-LOOK

Disk Algorithm Comparison

Algorithm Starvation Fairness Seek Time
FCFS No Very fair High
SSTF Yes Unfair Low
SCAN No Fair Medium
C-SCAN No Very uniform Medium
LOOK No Fair Low-Medium
C-LOOK No Very uniform Low-Medium

File Systems

File Concepts

File Access Methods

Method Description Use Case
Sequential Read/write in order Text files, logs
Direct (Random) Access any block directly Database files
Indexed Use index block to find records Indexed files

Directory Structures

Type Description Advantage Disadvantage
Single Level One directory for all files Simple Naming conflicts, no grouping
Two Level Separate directory per user Some isolation Still limited organization
Tree Hierarchical (folders/subfolders) Natural organization Path-based access
Acyclic Graph Shared subdirectories (no cycles) Sharing Complex (dangling pointers)
General Graph Full graph with cycles Maximum sharing Complex; garbage collection needed

Disk Allocation Methods

Method Description Advantage Disadvantage
Contiguous File occupies consecutive blocks Fast sequential access External fragmentation
Linked Each block has pointer to next No external frag No random access; pointer overhead
Indexed Index block contains pointers to all blocks Random access Index block overhead

Free Space Management

Method Description
Bitmap/Bit Vector Bit per block (0=free, 1=used); simple but large
Linked List Free blocks linked together
Grouping First free block addresses next group of free blocks
Counting List of (start, length) pairs for contiguous free blocks

File System Types

File System OS Key Features
FAT32 DOS/Windows Simple; no permissions; max 4GB file
NTFS Windows Journaling, permissions, encryption, compression
ext4 Linux Journaling, extents, large files, backward compatible
XFS Linux High performance, large files, journaling
ZFS Solaris/Linux Copy-on-write, snapshots, data integrity
APFS macOS Snapshots, cloning, encryption

I/O Systems

I/O Hardware

I/O Techniques

Programmed I/O (Polling)

Interrupt-Driven I/O

DMA (Direct Memory Access)

I/O Layer Stack

User Application
  
User-space I/O library
  
Kernel I/O subsystem (logical file system, VFS)
  
Device driver
  
Device controller (hardware)
  
I/O Device

Linux/Windows OS Basics

Linux Basics

Concept Description
Everything is a file Devices, processes, sockets all treated as files
Process Management fork() creates child process; exec() loads new program
File Permisions Read (4), Write (2), Execute (1) for owner/group/others: chmod 755 file
Superuser (root) UID = 0; highest privileges
Init System systemd (modern) or init (traditional); first process (PID 1)
Kernel Modules Loadable at runtime (insmod, rmmod, modprobe)
Shell Command interpreter (bash, zsh, sh)
File System Hierarchy / (root), /home, /etc, /var, /tmp, /usr, /bin, /sbin

Key Linux Commands

# Process management
ps aux          # List all processes
top             # Real-time process monitor
kill -9 PID     # Force kill process
nice -n 10 cmd  # Run with priority

# File operations
chmod 755 file  # Change permissions
chown user:grp  # Change ownership
ls -la          # List with details

# Disk management
df -h           # Disk free space
du -sh dir      # Directory size
mount /dev/sdX  # Mount filesystem

# Network
ifconfig        # Network interfaces
netstat -tuln   # Open ports
iptables        # Firewall rules

Windows OS Basics

Concept Description
Registry Central hierarchical database for system/application settings
NTFS Default file system; supports ACLs, encryption, compression
Services Background processes (managed via Services.msc)
Task Manager Process and performance monitoring
Active Directory Directory service for domain management
Windows Kernel Hybrid kernel (NT kernel)
DLL (Dynamic Link Library) Shared library; code reuse across applications

Linux vs Windows Comparison

Feature Linux Windows
Kernel Monolithic Hybrid (NT)
File System ext4, XFS, Btrfs NTFS, ReFS
Open Source Yes No
CLI Primary (shell) Secondary (PowerShell, CMD)
Permissions rwx (owner/group/others) ACL-based
Process Creation fork() + exec() CreateProcess()
Dominant Use Servers, embedded, cloud Desktop, enterprise

Key Formulas Summary

Concept Formula
CPU Utilization (CPU busy time / Total time) × 100
Throughput Processes completed / Time
Turnaround Time Completion Time - Arrival Time
Waiting Time Turnaround Time - Burst Time
Response Time First Response - Arrival Time
EAT (Virtual Memory) (1-p) × ma + p × page_fault_time
Disk Access Time Seek + Rotational Latency + Transfer
Exponential Averaging τₙ₊₁ = α×tₙ + (1-α)×τₙ
Page Fault Rate Page faults / Memory references
Banker's Safety Need[i] ≤ Work for some unfinished process

Exam Tips

  1. Process Scheduling: Practice numerical problems on FCFS, SJF, RR — most frequently tested
  2. Gantt Charts: Draw them for scheduling problems to avoid errors
  3. Banker's Algorithm: Practice safety check and resource request — guaranteed question
  4. Page Replacement: Know FIFO, LRU, Optimal — practice with reference strings
  5. Deadlock: All 4 conditions, prevention, avoidance, detection — comprehensive topic
  6. Disk Scheduling: SCAN vs C-SCAN vs LOOK — know the differences
  7. Synchronization: Semaphore solutions for producer-consumer, reader-writer
  8. Virtual Memory: Demand paging, thrashing, working set concept
  9. Memory Management: Paging vs segmentation — advantages and disadvantages
  10. Belady's Anomaly: Only in FIFO — important exam fact
  11. Context Switching: Understand what happens during a context switch
  12. Threads: User vs kernel threads; threading models

Practice Questions

11 MCQs for Operating Systems with detailed explanations.

Q1. Which of the following best describes Context switch time?

✅ Correct Answer: Option A

Explanation:
The correct answer is Option A — pure overhead — CPU does no useful work during the switch..

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option B — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q2. Regarding the following concept: 'Security and Access Control:...', which statement is correct?

✅ Correct Answer: Option B

Explanation:
The correct answer is Option B — Security and Access Control:.

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q3. Regarding the following concept: 'User Interface:...', which statement is correct?

✅ Correct Answer: Option B

Explanation:
The correct answer is Option B — User Interface:.

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q4. Regarding the following concept: 'Process Management:...', which statement is correct?

✅ Correct Answer: Option B

Explanation:
The correct answer is Option B — Process Management:.

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q5. Regarding the following concept: 'I/O System Management:...', which statement is correct?

✅ Correct Answer: Option C

Explanation:
The correct answer is Option C — I/O System Management:.

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option B — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q6. Regarding the following concept: 'File System Management:...', which statement is correct?

✅ Correct Answer: Option D

Explanation:
The correct answer is Option D — File System Management:.

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option B — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q7. Regarding the following concept: '| Multiple users share CPU time | UNIX, Linux |

|...', which statement is correct?

✅ Correct Answer: Option A

Explanation:
The correct answer is Option A — | Multiple users share CPU time | UNIX, Linux |
|.

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option B — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q8. Which of the following best describes critical section?

✅ Correct Answer: Option C

Explanation:
The correct answer is Option C — a code segment that accesses shared variables. Only one process should execute it at a time..

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option B — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q9. Which of the following best describes 2. Progress: If no process?

✅ Correct Answer: Option B

Explanation:
The correct answer is Option B — in CS, selection of next cannot be postponed.

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q10. Which of the following best describes - Page table itself?

✅ Correct Answer: Option B

Explanation:
The correct answer is Option B — paginated (too large to store contiguously).

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option C — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.


Q11. Which of the following best describes operating system?

✅ Correct Answer: Option C

Explanation:
The correct answer is Option C — system software that manages computer hardware, software resources, and provides common services for computer programs..

This concept is covered under Operating Systems in the CBDT Assistant Director Systems syllabus. The answer is established through standard definitions and widely accepted principles in the field.

Why other options are incorrect:
- Option A — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option B — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.
- Option D — This option is factually incorrect or describes a concept from a different domain, making it an invalid choice for this question.