Post

Basic - OS Structure

Basic - OS Structure

🧠 Operating System Basics — Kernel, Resources, System Calls, and Core Services

A developer‑oriented overview of what an Operating System (OS) does,
how it manages resources, enforces protection, and provides core system services.


1️⃣ What Is an Operating System?

An Operating System (OS) is software that manages hardware resources and provides a safe execution environment for programs.

System Resources

Resources are everything needed to run programs:

  • CPU time
  • Memory
  • Storage
  • I/O devices
  • Files
  • Processes & threads

Without an OS, programs must access hardware directly — complex, unsafe, and error‑prone.


2️⃣ User Space vs Kernel Space

AreaPurposeAccess Level
User SpaceNormal applicationsRestricted
Kernel SpaceOS core (hardware & memory control)Full control
  • The kernel is loaded into memory at boot.
  • Applications cannot directly access hardware.

3️⃣ Why We Need an OS (Embedded vs OS Example)

Bare‑Metal Example (No OS — ATmega)

1
2
3
4
5
6
7
8
9
10
11
12
#define DDRA  (*(volatile unsigned char*)0x3A)
#define PORTA (*(volatile unsigned char*)0x3B)

int main(void)
{
    DDRA = 0x01;
    PORTA = 0x01; // LED ON

    while (1) {
        // Infinite loop (no OS → no process scheduling or exit)
    }
}

Key Insight

  • No multitasking
  • No memory protection
  • No process isolation
  • Direct hardware register access

👉 An OS abstracts hardware and adds safety + multitasking.


4️⃣ Kernel — The Core of the OS

The kernel is responsible for:

  • Resource management
  • Process scheduling
  • Memory management
  • Device & driver control
  • System call handling

The kernel is the only software allowed to fully control hardware.


5️⃣ User Interface (UI)

The OS provides user interaction through:

  • GUI (Graphical User Interface) — Windows, macOS, Linux desktop
  • CLI (Command Line Interface) — Bash, PowerShell, Terminal

6️⃣ OS Core Services

6.1 Process Management

  • Creating, scheduling, and terminating processes
  • Context switching
  • Multitasking

6.2 CPU Scheduling

  • Decides which process runs next
  • Controls priority and CPU share

6.3 Memory Management

  • Allocation & deallocation
  • Paging & swapping
  • Virtual memory
  • Memory protection

6.4 I/O Device Management

  • Controls access to disks, keyboard, network, GPU
  • Buffers, queues, interrupt handling

6.5 File System Management

  • Stores data as files
  • Directory & permission handling
  • Storage abstraction

7️⃣ System Calls & Dual Mode (Protection Mechanism)

Applications cannot directly access hardware.

Instead:

They request services from the OS via System Calls.


Dual Mode Operation

ModePrivilegesPurpose
User ModeLimitedRun normal programs
Kernel ModeFullAccess hardware & memory
  • Controlled by Supervisor Flag in CPU status register
  • Prevents malicious or buggy apps from harming system

System Call — How Apps Enter Kernel Mode

A System Call is a controlled entry into kernel mode.

Example Flow

1
2
3
4
5
User Program
  ↓ system call
Kernel Mode
  ↓ access hardware / memory
Return to User Mode

Examples

  • read() — file input
  • write() — file output
  • fork() — create process
  • malloc() — request memory

👉 System calls act like a software interrupt.


8️⃣ OS Responsibilities Summary

CategoryOS Role
CPUScheduling & multitasking
MemoryAllocation, protection, paging
StorageFile system & disk management
DevicesDrivers & I/O control
SecurityAccess control & isolation
ProcessesLifecycle management

9️⃣ Developer Takeaways

✔ OS prevents direct unsafe hardware access
✔ Kernel enforces security & isolation
✔ System calls bridge user apps ↔ kernel
✔ OS scheduling determines performance & responsiveness
✔ Embedded systems without OS behave very differently


🧩 One‑Line Mental Model

The Operating System is the manager that safely shares hardware among all programs.

This post is licensed under CC BY 4.0 by the author.