Repository navigation
Operating Systems 01 overview
Relevant source files
The following references were used as context for generating this wiki page:
- Wikipedia: Operating system
- Wikipedia: Kernel (operating system)
- Wikipedia: System call
- Book: Silberschatz, Galvin and Gagne, Operating System Concepts
- Book: Arpaci-Dusseau and Arpaci-Dusseau, Operating Systems: Three Easy Pieces (free online)
An operating system (OS) is the program that manages a computer's hardware and lets other programs share it safely. It decides which program runs on the CPU, gives each program its own memory, keeps files on disk, talks to devices, and stops programs from interfering with each other. This wiki explains the core ideas for complete beginners and is organised around the questions asked in operating systems interviews.
How to read this wiki. Each page has an everyday analogy, diagrams, a worked problem where interviews use one, a "Common traps" list and a short set of interview questions with model answers. Diagrams, code and numbers are illustrative. Worked problems were calculated by hand for this wiki.
| # | Page | Interview topics |
|---|---|---|
| 1 | Overview | What an OS does, kernel vs user mode, the big picture |
| 2 | Processes | Process states, PCB, context switch, fork/exec/wait, zombies, IPC |
| 3 | Threads | Thread vs process, user vs kernel threads, what threads share |
| 4 | CPU Scheduling | FCFS, SJF, SRTF, Round Robin, priority, MLFQ, worked Gantt charts |
| 5 | Synchronization | Race conditions, mutex, semaphore, condition variable, classic problems |
| 6 | Deadlock | Four conditions, prevention, avoidance (banker's), detection, priority inversion |
| 7 | Memory Management | Fragmentation, paging, segmentation, page tables, TLB |
| 8 | Virtual Memory | Demand paging, page faults, replacement (FIFO, LRU, OPT), thrashing, copy-on-write |
| 9 | Files and I/O | Inodes, links, journaling, disk scheduling, interrupts, DMA |
| 10 | Kernel and System Calls | System call path, interrupts vs traps, monolithic vs microkernel, boot |
| 11 | Interview Q&A and Glossary | Quick-fire questions and all terms in one place |
The hardware side (caches, cores, memory ordering) is in the Computer Architecture wiki.
| Hotel | Operating system |
|---|---|
| Guests | Programs (processes) |
| Front desk | The kernel |
| Rooms, each with its own key | Each process's private memory (address space) |
| Shared facilities: lift, pool, kitchen | CPU, disk, network, devices |
| Booking the pool by time slots | CPU scheduling |
| "Ask the front desk; don't go into the boiler room" | System calls; user mode cannot touch hardware directly |
| Security stops one guest entering another's room | Memory protection |
flowchart TD
OS["Operating system"] --> P["Process management<br/>create, schedule, terminate"]
OS --> M["Memory management<br/>virtual memory, protection"]
OS --> F["File systems<br/>files, directories, permissions"]
OS --> IO["Device / I/O management<br/>drivers, interrupts"]
OS --> S["Security and protection<br/>users, permissions, isolation"]
OS --> N["Networking<br/>sockets, protocols"]
Two ways to describe the OS's job:
- Resource manager: shares limited CPU time, memory and devices fairly and efficiently between many programs.
- Abstraction provider: gives programs simple, portable ideas (processes, files, sockets, virtual memory) instead of raw hardware.
flowchart TB
U["User programs<br/>browser, shell, your code"] --> L["Libraries<br/>libc, runtime"]
L -->|"system calls"| K["Kernel<br/>scheduler, memory manager, file systems, drivers"]
K --> H["Hardware<br/>CPU, memory, disk, network"]
style K fill:#eef
| Mode | Who runs in it | What it may do |
|---|---|---|
| User mode | Applications and libraries | Ordinary instructions only; cannot touch devices or other processes' memory |
| Kernel mode (supervisor) | The kernel | Everything: configure the MMU, talk to devices, disable interrupts |
The CPU enforces the two modes in hardware (on Arm, exception levels EL0 for user and EL1 for kernel). A program enters the kernel only through a system call, an interrupt or an exception, covered in Kernel and System Calls.
Sources: Wikipedia: Operating system, Wikipedia: Kernel (operating system)
| Term | One-line meaning |
|---|---|
| Program | Code sitting in a file |
| Process | A program being run: code + memory + open files + CPU state |
| Thread | One flow of execution inside a process |
| Kernel | The always-resident core of the OS that runs in kernel mode |
| System call | A request from a program to the kernel (read, fork, mmap) |
| Context switch | Saving one thread's CPU state and loading another's |
| Virtual memory | Each process sees its own private address space |
| Interviewers often ask you to... | Practise on |
|---|---|
| Explain the difference between two things (process vs thread, mutex vs semaphore) | Every page's "Interview questions" |
| Work a small problem on a whiteboard (Gantt chart, banker's algorithm, page faults) | Scheduling, Deadlock, Virtual Memory, Files and I/O |
| Write synchronization code (producer-consumer, thread-safe counter) | Synchronization |
Trace what happens end to end ("what happens when you run ls?") |
Kernel and System Calls, Interview Q&A |
Count processes created by fork()
|
Processes |
- What is an operating system? Software that manages hardware resources and provides common services and abstractions to programs.
- Why do we need user and kernel mode? So a buggy or malicious program cannot crash the machine, read other programs' memory, or access devices directly; it must ask the kernel.
-
Is the shell part of the kernel? No. The shell is an ordinary user program that makes system calls such as
fork,execandwait.
- The OS manages CPU, memory, storage and devices, and provides processes, files and virtual memory.
- The kernel runs in privileged mode; programs reach it only through system calls, interrupts and exceptions.
- Interviews test definitions, comparisons, small worked problems and end-to-end traces.
- Computer Architecture Overview
- Fundamentals: CPU, Memory and Instructions
- Pipelining
- Branches and Remedies
- Instruction-Level Parallelism
- Memory and Ordering
- Caches and Coherence
- Multicore
- Multithreading in Hardware
- SIMD and GPUs
- Glossary and Summary
- Hexagon Overview and Processor Properties
- ISA Fundamentals: Packets, Slots and Threads
- Registers
- Instruction Encoding and Mnemonics
- Data, Memory and Control Instructions
- Floating Point, HVX and Alignment
- Caches, MMU and Glossary
- Operating Systems Overview
- Processes
- Threads
- CPU Scheduling
- Synchronization
- Deadlock
- Memory Management
- Virtual Memory
- Files, Storage and I/O
- Kernel and System Calls
- Interview Q&A and Glossary
- C++ for LLVM Development: Overview
- C++ Basics
- Classes and RAII
- Ownership and Move Semantics
- Templates and Lambdas
- LLVM Data Structures (ADT)
- LLVM-Style RTTI: isa, cast, dyn_cast
- Errors, Output and Assertions
- Iterators and Ranges
- Building, Debugging and Exercises
- LLVM IR Overview
- Structure: Modules, Functions, Blocks and Values
- Type System
- Arithmetic, Bitwise and Cast Instructions
- Compare and Select
- Memory: alloca, load, store and getelementptr
- Control Flow: br, switch, ret and call
- SSA and Phi
- Control Flow Graph and Loops
- Dominance, Dominator Tree and Dominance Frontier
- Data-flow Analysis
- Writing an IR Pass
- Common Passes
- Exercises, Tooling and Glossary
- SelectionDAG Overview
- Pipeline, Phases and Traversal Orders
- Core Data Structures
- DAG Construction
- DAG Combiner
- Legalization
- Type Legalization
- Operation and Vector Legalization
- Instruction Selection
- TableGen Pattern Language
- Matcher Interpreter and Folding
- AArch64 Instruction Selection
- Scheduling and MIR Emission
- PHI Node Resolution
- AArch64 Walkthroughs
- Arithmetic and Data Movement
- Memory Instructions
- Control Flow and Calls
- End-to-End Example
- Tooling, Debugging and Extending
- Selector Comparison and Glossary
- Assignments: Build the Toy Backend
- Stage 1: Build Setup
- Stage 2: Target Registration
- Stage 3: TableGen Skeleton
- Stage 4: MC Layer for Assembly Output
- Stage 5: TargetMachine and Subtarget
- Stage 6: TargetLowering, Arguments and Returns
- Stage 7: Instruction Selection and the First Function
- Stage 8: Registers, Copies and Spills
- Stage 9: Frame Lowering
- Stage 10: Memory, Globals and Control Flow
- Stage 11: Calls
- Stage 12: Scheduling Model
- Stage 13: Object Files
- Stage 14: Capstone, a Complete Toy Backend
- Target Bring-up Overview
- Directory Layout, CMake and Registration
- The Target .td File
- TargetMachine and Subtarget
- TargetLowering Setup
- Calling Conventions
- Instructions and Instruction Selection
- Registers and Allocation Hooks
- Frame Lowering
- AsmPrinter and the MC Layer
- Scheduling
- A Minimal Toy Target
- Bring-up Checklist and AArch64 File Map
- Tooling and Glossary
- Calling Conventions Overview
- The CallingConv.td Language
- CCState and CCValAssign
- LowerFormalArguments
- LowerCall
- LowerReturn and CanLowerReturn
- Varargs, byval, sret and swifterror
- Tail Calls and Sibling Calls
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- Frame Lowering Overview
- MachineFrameInfo
- TargetFrameLowering Hooks
- The PEI Pass
- Callee-Saved Registers and Stack Layout
- Frame Index Elimination and the Register Scavenger
- Shrink Wrapping
- CFI and Unwind Information
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- MC Layer Overview
- Core Data Structures
- Streamers
- Assembler and Layout
- Fixups and Relocations
- Writing an MC Layer for a Custom Backend
- MCAsmInfo and the Instruction Printer
- Code Emitter
- AsmBackend and Object Writer
- Assembly Parser and Disassembler
- Bring-up Checklist and Common Failures
- Tooling and Glossary
- Register Allocation Overview
- The Register Allocation Pipeline
- Registers, Virtual Registers and Register Classes
- Liveness: Slot Indexes and Live Intervals
- Preparing Code for Allocation
- PHI Elimination and Two-Address Lowering
- Register Coalescer
- Allocation Framework
- The Register Allocators
- Fast Register Allocator
- Basic Register Allocator
- Greedy Register Allocator
- PBQP Register Allocator
- Spilling and Splitting
- Spill Weights and Copy Hints
- The Inline Spiller
- Live Range Splitting
- Rewriting and Post-RA Passes
- Writing Register Allocation Support for a Custom Backend
- Register Definitions in TableGen
- TargetRegisterInfo Hooks
- TargetInstrInfo Hooks
- Pass Pipeline Hooks
- Bring-up Checklist and Common Failures
- AArch64 Walkthroughs
- Tooling and Debugging
- Glossary and Where Do I Look