Elective Operating System

Operating SystemUnit 1011 min read

Special Purpose Operating Systems: Types, Cloud OS, Embedded & Real-Time OS

Unit 10 of Operating System explores specialized operating systems beyond general-purpose OSes, covering cloud OS architectures, embedded systems, real-time OSes, and their unique design trade-offs. Learn how these systems power everything from smartphones to industrial control systems, with real-world examples and per

TAKEAWAYS:

  • Special-purpose OSes optimize for specific hardware, workloads, or environments (e.g., embedded OSes for sensors, real-time OSes for robotics).
  • Cloud OSes like Google’s Kubernetes or AWS’s Firecracker virtualize resources and manage distributed workloads with microkernel architectures.
  • Embedded OSes (e.g., FreeRTOS in smart meters) prioritize low power and determinism over features like GUI or multitasking.
  • Real-time OSes (e.g., QNX in medical devices) guarantee response times via priority scheduling and preemptive kernels.
  • Remote Procedure Call (RPC) enables transparent communication between distributed processes (used in WhatsApp’s backend).
  • Amoeba and Plan 9 demonstrate radical alternatives to Unix-like OSes with capability-based security and location transparency.

Core Concepts and Classifications

1. Why Special-Purpose OSes?

General-purpose OSes (e.g., Windows, Linux) are designed for flexibility but often include unnecessary overhead. Special-purpose OSes strip down features to meet specific constraints:

  • Hardware limitations (e.g., 8KB RAM in a sensor).
  • Performance requirements (e.g., 1ms response time in a pacemaker).
  • Security/certification needs (e.g., aviation or medical systems).
  • Cost (e.g., open-source embedded OSes like RIOT).
classDiagram
    class SpecialPurposeOS {
        <<abstract>>
        +optimizeFor(hardwareLimits, performance, security)
        +tradeOff(cost, flexibility, resourceUsage)
    }
    class EmbeddedOS {
        +lowPowerConsumption()
        +deterministicExecution()
        +examples: FreeRTOS, Zephyr
    }
    class RealTimeOS {
        +hardDeadline()
        +priorityScheduling()
        +examples: QNX, VxWorks
    }
    class CloudOS {
        +virtualization()
        +distributedProcessing()
        +examples: Kubernetes, Firecracker
    }
    SpecialPurposeOS <|-- EmbeddedOS
    SpecialPurposeOS <|-- RealTimeOS
    SpecialPurposeOS <|-- CloudOS

2. Embedded Operating Systems

Definition: OSes designed to run on dedicated hardware with limited resources, often without user interaction. Examples:

  • Smartphones (Android’s Linux kernel + HAL layers).
  • Smart meters (FreeRTOS).
  • Automotive ECUs (QNX, AUTOSAR).

Key Features:

Feature Embedded OS General-Purpose OS
Memory Usage <1MB (often <100KB) >1GB
Kernel Type Microkernel or RTOS kernel Monolithic/microkernel
Scheduling Priority-based, cooperative Time-sharing (round-robin)
File System FAT32, YAFFS (flash-optimized) ext4, NTFS
Power Management Critical (sleep modes, DVFS) Optional
Real-Time Support Hard/soft real-time Best-effort

Worked Example: Traffic Light Controller

Assume a traffic light system with:

  • 3 signals (red, yellow, green) per direction.
  • Sensor input for vehicle presence.
  • Constraints: Must switch lights within 50ms of sensor trigger.

Solution:

  1. Use FreeRTOS (embedded OS) with a priority-based scheduler.
  2. Tasks:
    • SensorTask (highest priority): Reads vehicle count, triggers LightTask.
    • LightTask (fixed priority): Updates timers for each light phase.
  3. Avoids blocking: Uses semaphores to signal LightTask without busy-waiting.
stateDiagram-v2
    [*] --> Idle
    Idle --> SensorTask : vehicle detected
    SensorTask --> LightTask : semaphore post
    LightTask --> Green : 30s
    LightTask --> Yellow : 5s
    LightTask --> Red : 25s
    LightTask --> [*]

3. Real-Time Operating Systems (RTOS)

Definition: OSes that guarantee worst-case execution time for critical tasks. Classified as:

  • Hard RTOS: Missed deadline = system failure (e.g., pacemakers, airbag deployment).
  • Soft RTOS: Deadline misses degrade performance (e.g., gaming consoles, robotics).

Key Mechanisms:

  1. Priority Scheduling:
    • Higher-priority tasks preempt lower-priority ones.
    • Example: In a drone, altitude control (P1) preempts camera feed processing (P3).
  2. Deterministic Timing:
    • No dynamic memory allocation (uses static pools).
    • Interrupt latency <10µs (vs. 1ms in Linux).
  3. Resource Reservation:
    • Rate Monotonic Scheduling (RMS): Shorter periods get higher priority.
    • Deadline Monotonic Scheduling (DMS): Earlier deadlines get higher priority.

Example: Medical Infusion Pump

  • Task 1: Monitor patient’s heart rate (period = 100ms, deadline = 100ms).
  • Task 2: Adjust drug dosage (period = 500ms, deadline = 500ms).
  • Task 3: Log data to SD card (period = 10s, deadline = 10s).

Scheduling:

  • RMS assigns priorities: Task 1 (P1) > Task 2 (P2) > Task 3 (P3).
  • Utilization: (well below the 0.693 limit for 3 tasks).

4. Cloud Operating Systems

Definition: OSes designed to manage virtualized, distributed resources across data centers. Examples:

  • Google’s Kubernetes (GKE): Orchestrates containers.
  • AWS Firecracker: Lightweight VMs for serverless apps.
  • Azure Arc: Extends cloud management to on-premises servers.
auto-scalingauto-scalingisolatedisolatedKubernetes MasterWorker Node 1Worker Node 2Firecracker VM 1Firecracker VM 2
Kubernetes orchestration with Firecracker VMs for secure transaction processing.

Key Features:

Feature Cloud OS Traditional OS
Resource Model Pools of VMs/containers Single machine
Scheduling Cluster-aware (e.g., Kubernetes) Per-process
Isolation Strong (containers/VMs) Weak (processes)
Scalability Horizontal (add nodes) Vertical (upgrade CPU/RAM)
APIs REST/gRPC (e.g., Kubernetes API) Syscalls

How Khalti’s Payment System Uses Cloud OS:

  1. Problem: Khalti processes 10,000+ transactions/sec during festivals.
  2. Solution:
    • Runs on Kubernetes (cloud OS) to auto-scale pods.
    • Uses Firecracker VMs for secure, isolated transaction processing.
    • Load balancing: Distributes requests across nodes via service meshes (e.g., Istio).
sequenceDiagram
    participant User
    participant KhaltiApp
    participant Kubernetes
    participant FirecrackerVM
    participant Database

    User->>KhaltiApp: Initiate payment
    KhaltiApp->>Kubernetes: Request VM (auto-scaled)
    Kubernetes-->>KhaltiApp: Assign FirecrackerVM
    KhaltiApp->>FirecrackerVM: Process transaction
    FirecrackerVM->>Database: Update ledger
    Database-->>FirecrackerVM: Confirm
    FirecrackerVM-->>KhaltiApp: Success
    KhaltiApp-->>User: Payment confirmed

Advanced Topics

5. Remote Procedure Call (RPC)

Definition: A protocol to call procedures on remote systems as if they were local. Used in:

  • WhatsApp: Calls backend services (e.g., send_message() on a remote server).
  • Nepal Rastra Bank’s Core Banking: RPCs for inter-bank transactions.

How RPC Works:

  1. Client marshals arguments into a binary format (e.g., Protocol Buffers).
  2. Stub sends the request over TCP/UDP.
  3. Server stub unmarshals and invokes the procedure.
  4. Response is marshaled and sent back.
sequenceDiagram
    participant Client
    participant Stub
    participant Network
    participant Server

    Client->>Stub: Marshal sendMoney(amount)
    Stub->>Network: TCP/UDP
    Network->>Server: Deliver
    Server->>Server: Invoke sendMoney()
    Server->>Database: Update balance
    Server-->>Stub: Marshal response
    Stub-->>Client: Unmarshal & return

Example: eSewa’s Payment RPC

  • Client: eSewa mobile app.
  • Server: eSewa’s backend (hosted on AWS).
  • RPC Call:
    # Pseudocode
    result = rpc.call("eSewaBackend", "process_payment", {
        "amount": 500,
        "user_id": "user123",
        "merchant_id": "shop456"
    })
    

6. Distributed OS Architectures: Amoeba and Plan 9

Amoeba System

  • Designed by: Andrew Tanenbaum (also creator of Minix).
  • Key Idea: Location transparency—processes communicate via capabilities (tokens granting access to objects).
  • Components:
    1. Workstations: User interfaces (e.g., X11).
    2. Servers: Store files, databases, etc.
    3. Capability Machine: Manages access control.
WorkstationsUser InterfaceServersFile/DB StorageCapability MachineAccess Control
Amoeba System Architecture: Decoupled components with capability-based security.

Example: In Amoeba, opening a file involves:

  1. Client requests a capability for /home/user/file.txt.
  2. Server validates the request and returns a capability.
  3. Client uses the capability to read/write (no path names).

Plan 9

  • Designed by: Bell Labs (same team as Unix).
  • Innovations:
    • 9P protocol: File systems over network (like NFS but simpler).
    • Inferno OS: Portable Plan 9 implementation (runs on ARM, x86).
    • Acme: Text-based window system (still used in research).

In the Real World

  1. Pathao’s Ride-Hailing System

    • Uses a real-time OS (QNX) in driver apps to ensure GPS updates every 200ms.
    • Cloud OS (Kubernetes) manages 100,000+ driver connections globally.
  2. Nepal Electricity Authority (NEA) Grid Monitoring

    • Embedded OS (FreeRTOS) runs on smart meters to report power usage every 5 minutes.
    • RPC syncs data to NEA’s central database (hosted on Linux).
  3. Ncell’s 4G Core Network

    • Cloud OS (OpenStack) virtualizes base stations to handle peak loads during festivals.
    • Docker containers isolate services (billing, authentication, routing).

Exam Tip

  1. Definitions:

    • Know the exact differences between embedded, RTOS, and cloud OSes (e.g., "RTOS guarantees deadlines; embedded OS minimizes power").
    • For RPC, explain the 4-step process (marshal → send → unmarshal → invoke).
  2. Diagrams:

    • Gantt charts (for scheduling in RTOS).
    • Sequence diagrams (for RPC or cloud OS interactions).
    • State diagrams (for embedded system tasks).
  3. Worked Examples:

    • RTOS: Always calculate utilization and check against the Liu & Layland bound ().
    • Cloud OS: Describe auto-scaling (e.g., "Kubernetes adds pods when CPU > 80%").
  4. Comparisons:

    • Memorize the trade-offs in this table:

      OS Type Priority Memory Use Power Use Use Case
      Embedded Low <1MB Ultra-low Sensors, IoT
      RTOS Hard deadlines <100MB Low Medical, aviation
      Cloud OS Cluster-wide GBs+ High Web apps, big data
  5. Common Pitfalls:

    • Don’t confuse:
      • Embedded OS (e.g., FreeRTOS) with general-purpose OS (e.g., Linux on a Raspberry Pi).
      • Hard RTOS (fails on deadline miss) with soft RTOS (degrades gracefully).
    • For RPC: Always mention stubs and marshalling.
  6. Past Exam Patterns:

    • Short notes: Expect 2x5 marks on context switching, PCB, or RPC.
    • Long questions: Focus on design trade-offs (e.g., "Why does Amoeba use capabilities?").
    • Numerical: Calculate waiting time or utilization for RTOS scheduling.

Based on the PU BE Computer (PU) syllabus for Operating System, unit 10.

Discussion

Loading…