Elective Operating System

Operating SystemUnit 117 min read

OS Basics: Definitions, Structures, Roles & Cloud OS

Unit 1 of Operating System covers the core concepts of operating systems—what they are, their types, functions, and how they manage hardware/software. It also introduces cloud operating systems, layered vs. monolithic structures, and real-world examples like eSewa and Ncell.

TAKEAWAYS:

  • An OS is a system software that acts as an intermediary between hardware and user programs, managing resources efficiently.
  • OS types (batch, time-sharing, real-time, distributed) are chosen based on performance needs (e.g., Ncell uses real-time OS for call routing).
  • Layered architecture improves modularity, while monolithic kernels offer speed (Linux uses a hybrid approach).
  • Cloud OS (e.g., AWS, Google Cloud) enables virtualization, scalability, and multi-tenancy for services like eSewa.
  • Context switching and PCB (Process Control Block) are critical for multitasking (e.g., Pathao’s ride-matching app).
  • Bottlenecks (e.g., slow disk I/O in Daraz’s order processing) are mitigated by OS optimizations like buffering.

1. What is an Operating System (OS)?

An OS is system software that manages hardware, provides a user interface, and executes applications efficiently. It acts as a bridge between users and hardware, ensuring smooth operation of computer systems.

Key Functions of an OS

mindmap
  root((Operating System Functions))
    OS_Hardware_Management["Hardware Management"]
      CPU_Scheduling["CPU Scheduling (Process Scheduling)"]
      Memory_Management["Memory Management (Allocation, Protection)"]
      Device_Management["Device Management (Driver Abstraction)"]
    Process_Management["Process Management"]
      Process_Creation["Process Creation (Fork, Exec)"]
      Process_Synchronization["Synchronization (Mutex, Semaphore)"]
      Deadlock_Handling["Deadlock Handling (Detection, Prevention)"]
    File_System_Management["File System Management"]
      File_Storage["File Storage (Allocation, Directory)"]
      File_Access["File Access (Permissions, Caching)"]
      Security["Security (Encryption, Authentication)"]
    User_Interface["User Interface"]
      CLI["CLI (Command Line Interface)"]
      GUI["GUI (Graphical User Interface)"]
    System_Calls["System Calls"]
      API["API (System Call Interface)"]
      Library_Functions["Library Functions (POSIX, WinAPI)"]

Why Do We Need an OS?

  • Resource Allocation: Ensures fair distribution of CPU, memory, and I/O devices.
  • Security: Protects system resources from unauthorized access (e.g., bank transactions in Ncell).
  • Convenience: Provides a user-friendly interface (e.g., Windows, Linux).
  • Efficiency: Optimizes system performance (e.g., Daraz’s order processing uses OS scheduling).

2. Types of Operating Systems

OS types are classified based on their design goals and usage scenarios. Below is a comparison table:

Type Description Example Use Case
Batch OS Executes jobs in batches without user interaction. Early IBM OS Legacy mainframe systems.
Time-Sharing OS Allows multiple users to share a single system simultaneously. UNIX, Linux University labs, cloud servers.
Real-Time OS (RTOS) Guarantees a deterministic response time (critical for time-sensitive tasks). VxWorks, FreeRTOS Medical devices, Ncell call routing.
Distributed OS Manages multiple interconnected systems as a single OS. Amoeba, Plan 9 Google Cloud, eSewa’s distributed servers.
Multiprocessing OS Supports multiple CPUs for parallel processing. Windows Server, Linux High-performance computing.
Embedded OS Runs on embedded systems (limited resources). Android (for smartphones), FreeRTOS Smartwatches, IoT devices.
Mobile OS Optimized for mobile devices (touch interfaces, battery efficiency). Android, iOS Pathao, Daraz mobile apps.
Cloud OS Enables virtualization and multi-tenancy for cloud computing. AWS, Google Cloud OS eSewa, Khalti (scalable backend).

Real-World Example: Ncell’s Real-Time OS

Ncell’s call routing system uses a real-time OS to ensure:

  • Low latency (calls connect in <1 second).
  • Deterministic scheduling (no delays in emergency calls).
  • Fault tolerance (calls reroute if a tower fails).

3. Structure of Operating Systems

OS structures define how the OS is organized and implemented. The two main types are:

User InterfaceGUI/CLISystem CallsSystem CallKernelKernel ModulesHardwareCPU/Memory
Typical OS layer hierarchy (e.g., Linux kernel)

A. Monolithic Kernel

  • Single large executable with all OS functions (CPU scheduling, memory management, file systems) in one block.
  • Pros:
    • Fast (no inter-process communication overhead).
    • Simple to implement.
  • Cons:
    • Less secure (a bug in one module can crash the entire system).
    • Hard to maintain (large codebase).
  • Example: Early versions of Windows NT, UNIX (BSD).

B. Layered (Modular) Architecture

  • OS is divided into layers, each with a specific function.
  • Pros:
    • Modularity: Easier to debug and update.
    • Security: Lower layers are protected from upper layers.
  • Cons:
    • Slower (function calls between layers add overhead).
  • Example: THE Multics OS, some research OS.

Comparison Table

Feature Monolithic Kernel Layered Architecture
Structure Single large block Modular layers
Speed Faster (direct hardware access) Slower (layer overhead)
Security Less secure (single point of failure) More secure (isolation)
Maintainability Hard (large codebase) Easier (modular updates)
Examples Windows NT, UNIX (BSD) THE Multics, some research OS

Modern Hybrid Approach: Linux Kernel

Linux uses a hybrid model:

  • Monolithic core for performance-critical tasks (CPU scheduling, memory).
  • Loadable kernel modules for optional features (e.g., Wi-Fi drivers, file systems).

4. Cloud Operating System (Cloud OS)

A Cloud OS is designed to run on cloud infrastructure, enabling:

  • Virtualization (multiple VMs on a single physical machine).
  • Scalability (resources dynamically allocated).
  • Multi-tenancy (multiple users share the same OS instance securely).

Key Characteristics

mindmap
  root((Cloud OS Characteristics))
    Virtualization["Virtualization"]
      VMs["Virtual Machines (KVM, Hyper-V)"]
      Containers["Containers (Docker, Kubernetes)"]
    Scalability["Scalability"]
      Horizontal["Horizontal Scaling (Auto-scaling)"]
      Vertical["Vertical Scaling (Instance Upgrade)"]
    Multi_tenancy["Multi-tenancy"]
      Isolation["Isolation (Network, Storage)"]
      Resource_Pooling["Resource Pooling (Elasticity)"]
    API_Driven["API-Driven Management"]
      REST["RESTful APIs (AWS, Azure)"]
      SDKs["SDKs (AWS SDK, Google Cloud SDK)"]
    Fault_Tolerance["Fault Tolerance"]
      Redundancy["Redundancy (Multi-AZ Deployment)"]
      Load_Balancing["Load Balancing (DNS, ALB)"]

Advantages of Cloud OS

Advantage Explanation Real-World Example
Cost Efficiency Pay-as-you-go model (no need for physical hardware). eSewa uses AWS to scale during Diwali.
Scalability Instantly add/remove resources based on demand. Khalti handles millions of transactions.
Disaster Recovery Automated backups and failover mechanisms. Google Cloud for NTC’s network redundancy.
Global Access Deploy services worldwide with low latency. Daraz’s cloud-based inventory system.
Security Built-in encryption and access controls. Bank of Kathmandu’s cloud banking.

Example: eSewa’s Cloud OS

eSewa uses AWS Cloud OS to:

  1. Host virtual servers (instead of physical machines).
  2. Auto-scale during peak hours (e.g., Dashain, Tihar).
  3. Secure transactions using AWS’s multi-tenancy isolation.

5. Context Switching and Process Control Block (PCB)

t0Process A Runningt1Interrupt (ProcessB ready)t2Process B Runningt3Context SwitchOverhead
Context switching steps between Process A and B

A. Context Switching

When the OS switches from one process to another, it saves the current process’s state and loads the next one. This is called context switching.

Steps in Context Switching:

  1. Save the state of the current process (registers, program counter, memory maps).
  2. Update the PCB (Process Control Block) of the current process.
  3. Load the state of the next process from its PCB.
  4. Resume execution of the new process.

Overhead of Context Switching:

  • Time taken to switch processes (~1-10 ms, depending on the OS).
  • Memory usage (PCBs consume memory).
  • CPU cycles wasted (not executing user code).

Real-World Example: Pathao’s Ride-Matching

Pathao’s app uses context switching to:

  • Alternate between:
    • Driver location tracking (GPS updates).
    • Passenger request processing (matching algorithms).
  • Ensures low latency (<2 seconds for ride assignment).

B. Process Control Block (PCB)

A PCB is a data structure that stores all information about a process. It includes:

mindmap
  root((Process Control Block (PCB)))
    Process_ID["Process ID (PID)"]
    Process_State["State (New → Ready → Running → Waiting → Terminated)"]
    Program_Counter["Program Counter (Instruction Pointer)"]
    CPU_Registers["CPU Registers (General, Special)"]
    CPU_Scheduling_Info["Scheduling Info (Priority, Queue Pointer)"]
    Memory_Management_Info["Memory Info (Base/Limit, Page Tables)"]
    I_O_Status_Info["I/O Status (Requests, Device Allocation)"]
    Accounting_Info["Accounting (CPU Time, Process Owner)"]
    Parent_PID["Parent Process ID (PPID)"]
    Process_Stack["Process Stack (Return Addresses)"]

Example PCB in Linux:

# Example PCB fields in Linux (simplified)
struct task_struct {
    pid_t pid;                  // Process ID
    enum task_state state;      // Process state (TASK_RUNNING, etc.)
    unsigned long flags;        // Process flags
    struct mm_struct *mm;       // Memory management info
    struct thread_struct thread; // CPU registers
    unsigned long ptrace_message; // Debugging info
    // ... other fields
};

6. Bottlenecks in Operating Systems

A bottleneck occurs when a component slows down the entire system. Common bottlenecks in OS:

Bottleneck Type Cause Example Solution
CPU Bottleneck CPU is overloaded (too many processes). Daraz’s order processing during sales. Use better scheduling algorithms.
Memory Bottleneck Insufficient RAM (too many applications open). Slow performance in low-end PCs. Use virtual memory (swap space).
I/O Bottleneck Slow disk I/O (e.g., HDD vs. SSD). Ncell’s old billing systems. Use SSDs, caching, RAID.
Network Bottleneck High latency in data transfer. Lag in online banking (e.g., NMB). Use CDNs, load balancers.

Real-World Example: Kathmandu Traffic (Network Bottleneck)

  • Problem: During peak hours, NTC’s network gets congested (bottleneck at routers).
  • Solution:
    • Load balancing (distribute traffic across multiple servers).
    • Caching (store frequently accessed data closer to users).

7. Exam Tip: How to Score Full Marks

Common Exam Patterns for Unit 1

  1. Define and Discuss:

    • Example: "Define OS. Explain monolithic vs. layered architecture."
    • How to Answer:
      • Start with a clear definition (1 mark).
      • Use a comparison table (3 marks).
      • Add real-world examples (e.g., Linux vs. Windows NT) (2 marks).
  2. Short Notes (2x5):

    • Example: "Write short notes on: (a) Context Switching (b) PCB."
    • How to Answer:
      • Context Switching:
        • Define in 1 line.
        • Explain steps (3 bullet points).
        • Mention overhead and real-world use (Pathao).
      • PCB:
        • List 5 key fields (PID, state, registers, etc.).
        • Draw a simple diagram (if allowed).
  3. Diagram-Based Questions:

    • Example: "Illustrate how CPU switches from one process to another."
    • How to Answer:
      • Draw a state transition diagram (Ready → Running → Waiting).
      • Label PCB updates and context switching steps.
  4. Cloud OS Questions:

    • Example: "Discuss characteristics and advantages of Cloud OS."
    • How to Answer:
      • List 4 characteristics (virtualization, scalability, multi-tenancy, API-driven).
      • Give 2 advantages (cost efficiency, disaster recovery).
      • Real-world tie-in: eSewa/Khalti using AWS.

Marks Distribution (Typical)

Section Marks How to Maximize
Definition 1 Concise, accurate definition.
Explanation 3-4 Use bullet points, diagrams, tables.
Real-World Example 2 Tie to Nepali companies (eSewa, Ncell).
Comparison 3 Side-by-side table (monolithic vs. layered).
Diagram 2 Mermaid/hand-drawn (PCB, state transitions).

8. Worked Example: Calculating Context Switching Overhead

Problem: A system has 100 processes, each requiring 5 ms for context switching. If the CPU spends 10% of its time on context switching, calculate:

  1. Total time lost to context switching in 1 hour.
  2. How many processes can run in 1 second if each process runs for 20 ms?

Solution:

  1. Time lost in 1 hour:

    • Total CPU time in 1 hour = .
    • Time lost to context switching = .
  2. Processes per second:

    • Each process runs for 20 ms + 5 ms (context switch) = 25 ms.
    • Processes per second = .

Real-World Tie-In:

  • Pathao’s ride-matching server must minimize context switching to handle 10,000+ requests per second.
  • If each context switch takes 5 ms, the server would lose 50,000 ms (50 seconds) per hour just on switching—inefficient!
  • Solution: Use event-driven programming (reduce context switches).

9. Summary Table: Key Concepts

Concept Definition Example Exam Tip
Operating System Software that manages hardware/software resources. Windows, Linux Define + 4 functions (CPU, memory, etc.).
Monolithic Kernel Single block of code for all OS functions. Windows NT Compare with layered (speed vs. security).
Layered OS Modular structure (each layer has a specific role). THE Multics Draw a layered diagram.
Cloud OS Enables virtualization, scalability, and multi-tenancy in cloud environments. AWS, Google Cloud OS Mention eSewa/Khalti as examples.
Context Switching Saving/restoring process state to switch between tasks. Pathao’s ride-matching Explain overhead and PCB.
PCB Data structure storing process information. Linux task_struct List 5 key fields.
Bottleneck Component that slows down the entire system. NTC network congestion Give solutions (load balancing).

10. Final Checklist Before Exam

  • Can you define OS in one line?
  • Can you compare monolithic vs. layered OS?
  • Can you explain Cloud OS with a real-world example (eSewa/Khalti)?
  • Can you draw a PCB diagram or context switching steps?
  • Can you identify bottlenecks in a system (e.g., Daraz’s order processing)?
  • Can you calculate context switching overhead (like in the worked example)?

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

Discussion

Loading…