Introduction to Operating Systems

An Operating System (OS) is the most critical software that runs on a computer. It acts as an intermediary between the user, applications, and the computer hardware. The OS manages hardware resources, provides services to application programs, and creates an environment where users can interact with the system efficiently.

From the moment you press the power button, the OS takes control — initializing hardware, loading essential services, and providing the interface that allows you to run applications. Whether it's Windows, macOS, Linux, Android, or iOS, every operating system performs the same fundamental functions: process management, memory management, file system management, device management, and security.

💡 Why It Matters: Understanding operating system architecture is essential for system programmers, software developers, and IT professionals. It helps you write more efficient code, debug complex issues, and design scalable applications that leverage hardware resources effectively.

1. Operating System Layers & Architecture

1.1 The Layered Architecture

Modern operating systems are organized into layers, each providing services to the layer above while hiding implementation details from layers below.

Operating System Layered Architecture User Applications (Web Browsers, Games, Office) System Libraries & APIs (System Calls, DLLs) Kernel (Process, Memory, File, Device Management) Hardware Abstraction Layer (HAL) Hardware (CPU, RAM, Disks, Network, Peripherals) Each layer provides services to the layer above while abstracting hardware complexity System Calls: The interface between applications and the kernel
Figure 1: Operating System Layered Architecture — each layer abstracts complexity from the layer above.

1.2 Kernel Types

Kernel TypeDescriptionExamples
Monolithic KernelAll OS services run in kernel space. Fast but less stable.Linux, Unix, Windows (hybrid)
MicrokernelMinimal kernel; services run in user space. More stable but slower.QNX, macOS (hybrid), MINIX
Hybrid KernelCombines monolithic and microkernel approaches.Windows NT, macOS XNU
ExokernelMinimal abstraction; applications manage hardware directly.MIT Exokernel, Nemesis
🔧 Kernel Space vs User Space:
  • Kernel Space: Privileged mode where kernel executes. Direct hardware access. If a kernel process crashes, entire system crashes.
  • User Space: Unprivileged mode where applications run. Isolated from hardware. If an app crashes, OS continues running.

2. Process Management

A process is a program in execution. The OS manages processes through creation, scheduling, and termination. Each process has its own address space, registers, and program counter.

2.1 Process States

Process State Diagram New Ready Running Terminated Waiting Admitted Scheduler Exit I/O / Event Wait I/O / Event Complete
Figure 2: Process State Diagram — processes transition through New → Ready → Running → Waiting → Terminated.

2.2 Process Control Block (PCB)

Each process is represented by a PCB containing:

2.3 Context Switching

Context switching is the process of saving the state of a running process and loading the state of another process. The scheduler determines which process runs next.

// Simplified context switch illustration
struct Process {
    int pid;
    int program_counter;
    int registers[16];
    int *memory_map;
};

void context_switch(Process* current, Process* next) {
    save_state(current);      // Save current process state
    restore_state(next);      // Restore next process state
    // CPU now executes next process
}

2.4 Scheduling Algorithms

The scheduler decides which process runs next. Key algorithms:

AlgorithmDescriptionProsCons
First-Come, First-Served (FCFS)Processes execute in arrival orderSimple, fairConvoy effect, poor response time
Shortest Job First (SJF)Shortest CPU burst firstOptimal average waiting timeStarvation, needs burst time prediction
Round Robin (RR)Time quantum; cyclic executionFair, good response timeContext switch overhead
Priority SchedulingHigher priority runs firstSupports real-time tasksStarvation possible
Multilevel Feedback QueueMultiple queues with agingAdaptive, balances I/O and CPU boundComplex to implement
⏱️ Round Robin Example: With time quantum = 4ms
  • Processes: P1 (8ms), P2 (5ms), P3 (2ms)
  • Execution order: P1(4) → P2(4) → P3(2) → P1(4) → P2(1)
  • Average wait time: (4+3+6)/3 = 4.33ms

3. Threads and Concurrency

Threads are lightweight processes that share the same address space. They enable parallelism and efficient resource utilization.

Process vs Threads Process Code Data Files Stack Threads (within a process) Thread 1 Stack Thread 2 Stack Thread 3 Stack Shared: Code, Data, Files, Heap
Figure 3: Process vs Threads — threads share address space, enabling efficient communication.

3.1 Synchronization Primitives

Concurrent access to shared resources requires synchronization to prevent race conditions.

// Mutex example in C
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

void* thread_function(void* arg) {
    pthread_mutex_lock(&lock);
    // Critical section - only one thread at a time
    shared_counter++;
    pthread_mutex_unlock(&lock);
    return NULL;
}

3.2 Deadlock

Deadlock occurs when two or more processes wait indefinitely for resources held by each other.

⚠️ Deadlock Conditions (Coffman Conditions):
  1. Mutual Exclusion: Resources cannot be shared
  2. Hold and Wait: Process holds resources while waiting for others
  3. No Preemption: Resources cannot be forcibly taken
  4. Circular Wait: Circular chain of waiting processes
Deadlock: Circular Wait P1 P2 P3 R1 Each process holds resource needed by next
Figure 4: Deadlock — circular wait condition.

4. Memory Management

Memory management is responsible for allocating and deallocating memory to processes, ensuring efficient utilization and protection.

4.1 Memory Allocation Techniques

4.2 Virtual Memory

Virtual memory abstracts physical memory, giving each process its own address space. It enables:

Virtual Memory: Page Table Translation Virtual Address Space P0 P1 P2 Page Table 2 0 1 Physical Memory F0 F1 F2 Page Table maps virtual pages to physical frames
Figure 5: Virtual Memory — page table translates virtual addresses to physical frames.

4.3 Page Replacement Algorithms

When physical memory is full, the OS must choose which page to evict:

📊 Thrashing: When a system spends more time swapping pages than executing processes. Caused by insufficient physical memory. Solutions: increase RAM, reduce process count, or implement better page replacement.

5. File Systems

File systems organize and manage persistent storage, providing a hierarchical structure for data organization.

5.1 File System Structure

Hierarchical File System / (root) /home /etc /var /usr alice/ bob/ passwd log/ bin/ Files and directories organized in tree structure
Figure 6: Hierarchical File System — root directory contains subdirectories and files.

5.2 File Allocation Methods

5.3 Popular File Systems

File SystemOSFeatures
ext4LinuxJournaling, backward compatibility, large file support
NTFSWindowsJournaling, encryption, compression, permissions
APFSmacOS/iOSCopy-on-write, snapshots, encryption
ZFSSolaris, FreeBSDBuilt-in RAID, compression, snapshots, data integrity

6. I/O Management

The OS manages all input/output operations, providing a uniform interface for devices while handling device-specific details.

6.1 I/O Techniques

6.2 Device Drivers

Device drivers are kernel modules that provide a standard interface to hardware devices. They handle device-specific commands, interrupt handling, and data transfer.

7. Security and Protection

Operating systems implement multiple layers of security to protect resources and user data.

7.1 Protection Mechanisms

7.2 Authentication and Authorization

🔐 Modern OS Security Features:
  • Address Space Layout Randomization (ASLR) — prevents buffer overflow exploits
  • Data Execution Prevention (DEP) — prevents code execution from data segments
  • Secure Boot — ensures only signed OS components load
  • Sandboxing — isolates applications (containers, virtual machines)

8. Real-World Operating Systems

8.1 Linux

Open-source, monolithic kernel. Dominant in servers, supercomputers, and embedded systems. Features: modular kernel, extensive hardware support, strong security.

8.2 Windows NT Architecture

Hybrid kernel with microkernel influences. Features: Win32 API, registry, NTFS, robust security model.

8.3 macOS / iOS (XNU)

Hybrid kernel combining Mach microkernel and BSD components. Features: Unix compliance, advanced graphics (Core Graphics), sandboxed apps.

8.4 Android (Linux-based)

Linux kernel with modified userspace. Features: application sandboxing, Dalvik/ART runtime, HAL for device support.

Conclusion

Operating System Architecture is the foundation upon which all computing experiences are built. From process scheduling to memory management, from file systems to security, the OS provides the essential services that enable applications to run efficiently and securely.

Understanding these concepts is crucial for system programmers, software architects, and anyone seeking to optimize application performance or troubleshoot complex system issues.

📚 Next Steps: Continue your exploration with Database Management Systems, Computer Networking Protocols, or dive deeper into AI and Machine Learning.