What is an Operating System?#

An OS is the software layer between hardware and applications. It manages resources (CPU, memory, disk, I/O) and provides abstractions so programs don’t need to interact with hardware directly.

flowchart TD
    Apps["Applications (browser, editor, server)"]
    Apps --> OS["Operating System"]
    OS --> HW["Hardware (CPU, RAM, Disk, Network)"]

Core Responsibilities#

FunctionWhat It Does
Process managementCreate, schedule, and terminate processes
Memory managementAllocate RAM, virtual memory, paging
File systemOrganize and access persistent data
I/O managementInterface with devices (disk, network, display)
SecurityUser permissions, process isolation

Process Management#

What is a Process?#

A process is a running program — it has its own memory space, file descriptors, and execution state.

stateDiagram-v2
    [*] --> New: Created
    New --> Ready: Admitted
    Ready --> Running: Scheduled
    Running --> Ready: Preempted
    Running --> Waiting: I/O request
    Waiting --> Ready: I/O complete
    Running --> Terminated: Exit

Process vs Thread#

AspectProcessThread
MemoryOwn address spaceShared with other threads
Creation costHigh (fork)Low
CommunicationIPC (pipes, sockets)Shared memory
IsolationFullNone (crash affects all threads)
ExampleEach Chrome tabMultiple workers in a web server

Scheduling#

The OS decides which process gets CPU time:

AlgorithmDescriptionUse Case
Round RobinFixed time slice per processGeneral purpose
PriorityHigher priority runs firstReal-time systems
CFS (Completely Fair)Proportional CPU timeLinux default
FIFOFirst come, first servedBatch processing

Context Switch#

When the OS switches from one process to another:

  1. Save current process state (registers, program counter)
  2. Load next process state
  3. Resume execution

Context switches are expensive (~1-10μs) — too many = poor performance.


Memory Management#

Virtual Memory#

Each process sees its own private address space — the OS maps virtual addresses to physical RAM:

flowchart LR
    subgraph Process["Process View"]
        Stack["Stack (grows down)"]
        Heap["Heap (grows up)"]
        Data["Data (globals)"]
        Code["Code (text)"]
    end
    
    Process -->|"Page Table"| RAM["Physical RAM"]
    Process -->|"Page Table"| Swap["Swap (disk)"]

Key Concepts#

ConceptDescription
Virtual addressAddress the process uses (not physical)
PageFixed-size block (typically 4KB)
Page tableMaps virtual pages → physical frames
Page faultAccessing a page not in RAM → load from disk
SwapDisk space used as overflow when RAM is full
OOM KillerLinux kills processes when memory is exhausted

Why Virtual Memory?#

  • Isolation — processes can’t access each other’s memory
  • Simplicity — every process thinks it has all memory to itself
  • Overcommit — total virtual memory can exceed physical RAM

Kernel vs User Space#

flowchart TD
    subgraph User["User Space"]
        App1["Application 1"]
        App2["Application 2"]
        Lib["Libraries (libc)"]
    end
    
    User -->|"System Calls"| Kernel["Kernel Space"]
    
    subgraph Kernel
        Sched["Scheduler"]
        MM["Memory Manager"]
        FS["File System"]
        Drivers["Device Drivers"]
    end
    
    Kernel --> HW["Hardware"]
SpaceAccessContains
User spaceRestrictedApplications, libraries
Kernel spaceFull hardware accessOS core, drivers

System calls are the interface between user space and kernel (e.g., open(), read(), write(), fork(), exec()).


Types of Operating Systems#

TypeExamplesUse Case
DesktopWindows, macOS, UbuntuPersonal computing
ServerLinux (Ubuntu, RHEL, Amazon Linux)Cloud, web servers
MobileAndroid, iOSPhones, tablets
EmbeddedFreeRTOS, ZephyrIoT, appliances
Real-time (RTOS)VxWorks, QNXIndustrial, automotive

Linux Dominance in Servers#

~96% of cloud servers run Linux because:

  • Free and open source
  • Stable and secure
  • Lightweight (no GUI needed)
  • Excellent tooling and automation
  • Container-native (cgroups, namespaces)

Key Takeaways#

  1. The OS manages resources — CPU (scheduling), memory (virtual memory), I/O (drivers)
  2. Processes are isolated — each has its own memory space
  3. Threads share memory — faster but less safe than processes
  4. Virtual memory provides isolation and allows overcommit
  5. System calls are how programs request OS services
  6. Linux dominates servers — understanding it is essential for backend/cloud work