हिंदी में: ऑपरेटिंग सिस्टम कंप्यूटर के सभी संसाधनों का मैनेजर है — प्रोसेस, मेमोरी, फ़ाइल और डिवाइस।
What is an operating system?
An operating system (OS) is system software that manages hardware resources and provides services to programs and users. It acts as an intermediary between applications and hardware. Examples: Linux, Windows, macOS, Android, iOS.
Main functions: process management, memory management, file management, device (I/O) management, security and protection, and providing a user interface (CLI or GUI).
The kernel is the core of the OS. Programs request OS services through system calls (e.g. fork(), read(), write() on Unix-like systems). Kernels can be monolithic (Linux), microkernel (Minix, QNX) or hybrid (Windows NT, macOS XNU).
Processes and threads
A process is a program in execution, with its own memory space. Its information is kept in a Process Control Block (PCB): process ID, state, program counter, registers, open files and more.
Process states: New → Ready → Running → Waiting (blocked) → Terminated.
A thread is a lightweight unit of execution inside a process. Threads of the same process share code, data and open files but have their own stack and registers, so creating and switching threads is cheaper than processes.
CPU scheduling
The scheduler decides which ready process runs next.
| Algorithm | Idea | Note |
|---|---|---|
| FCFS | First come, first served | Simple; can cause the convoy effect |
| SJF / SRTF | Shortest job (remaining time) first | Minimum average waiting time; can starve long jobs |
| Priority | Highest priority first | Starvation fixed by aging |
| Round Robin | Each process gets a fixed time quantum | Good for time-sharing; quantum size matters |
| Multilevel queue | Separate queues for different process types | Used in real systems |
Useful terms: turnaround time = completion − arrival; waiting time = turnaround − burst; response time = first run − arrival.
Process synchronization
When processes share data, a race condition can produce wrong results. The code that accesses shared data is the critical section. A correct solution must provide mutual exclusion, progress and bounded waiting.
Tools: mutex locks, semaphores (counting and binary, with wait()/signal()), and monitors. Classic problems: producer–consumer (bounded buffer), readers–writers, dining philosophers.
Deadlock
A set of processes is deadlocked when each waits for a resource held by another. Four necessary conditions (Coffman):
- Mutual exclusion
- Hold and wait
- No preemption
- Circular wait
Handling strategies: prevention (break one condition), avoidance (Banker’s algorithm keeps the system in a safe state), detection and recovery, or ignoring it (the “ostrich” approach used by many general-purpose OSes).
Memory management
- Contiguous allocation with first-fit, best-fit, worst-fit — suffers from fragmentation.
- Paging: memory is divided into fixed-size frames, programs into pages; a page table maps pages to frames. No external fragmentation. A TLB caches recent translations.
- Segmentation: memory divided into logical segments (code, stack, data).
Virtual memory
Virtual memory lets a program use more memory than physically available by keeping only the needed pages in RAM (demand paging). A missing page causes a page fault, and the OS loads it from disk.
Page replacement algorithms: FIFO (can show Belady’s anomaly), Optimal (theoretical best), LRU (least recently used — a practical approximation of optimal).
Thrashing happens when the system spends more time swapping pages than executing.
File systems and storage
A file system organises data on disk into files and directories (e.g. ext4, NTFS, FAT32, APFS). Allocation methods: contiguous, linked, indexed (inodes in Unix). Disk scheduling algorithms such as FCFS, SSTF, SCAN and C-SCAN reduce seek time on hard disks.
Quick revision
- Process = program in execution; thread = lightweight process.
- Round Robin is preemptive; FCFS is not.
- Deadlock needs all four Coffman conditions.
- LRU approximates optimal page replacement; FIFO can suffer Belady’s anomaly.