Operating System Concepts: Key Components & Mechanisms

Operating System Concepts

Extended Machine: Turns hardware into user-friendly abstractions.

Resource Management

Resource Manager: Manages hardware resources (CPU, memory, I/O).

CPU Architecture

CPU Pipeline: Breaks instructions into stages for parallel execution.

Superscalar CPU: Executes multiple instructions per clock cycle.

Memory Hierarchy

Memory Hierarchy: Registers → Cache (L1, L2, L3) → Main Memory (RAM) → Disk.

Bus Structure

Bus Structure: Connects CPU, memory, and I/O devices.

Types of Buses: Data bus, address bus, control bus.

Process Management

Process: A program in execution.

Process Tree: Parent processes create child processes (e.g., Process A creates B and C).

Process Resources: Address space, files, registers, etc.

System Calls

System Calls: Interface between user programs and the OS.

Process Management System Calls

Process Management: fork(), exec(), wait(), exit().

File Management System Calls

File Management: open(), read(), write(), close().

Directory Management System Calls

Directory Management: mkdir(), rmdir(), link(), unlink().

POSIX and Win32 APIs

POSIX System Calls: Standardized system calls for UNIX-like systems.

Win32 API: Windows equivalent of POSIX system calls.

Kernel Types

Monolithic: Main program + service procedures + utility procedures. All-in-one, fast (UNIX).

Microkernels: Minimal OS kernel, most services run in user space (MINIX3).

Virtual Machines

Virtual Machines:

Type 1 Hypervisor: Runs directly on hardware (e.g., VMware ESXi).

Type 2 Hypervisor: Runs on top of an OS (e.g., VirtualBox).

Kernel Details

Kernel: Manages resources.

Kernel Panic: Crash (e.g., BSOD) when low-level functions fail.

Drivers: Built-in → works or doesn’t; no updates.

Microkernel: Only basic functions (processes, syscalls).

Fast: Direct calls to code.

Modular: Build systems on top of it.

Microkernel: Minimal, modular, reliable.

Processes and Multiprogramming

Process: A program in execution.

Multiprogramming: Multiple processes in memory, sharing the CPU.

Process States

Process States:

  • Running: Using the CPU.
  • Ready: Waiting for CPU time.
  • Blocked: Waiting for an event (I/O).

Process Termination

Process Termination:

  • Voluntary: Normal exit, error exit.
  • Involuntary: Fatal error, killed by another process.

Concurrency Control

Semaphore: Is essentially a counter that controls access to a shared resource.

Semaphores are used to ensure that:

  • The producer doesn’t add items to a full buffer.
  • The consumer doesn’t remove items from an empty buffer.

Deadlock: Two processes waiting for each other.

Mutex: Used to protect shared resources from being accessed simultaneously by multiple threads or processes, ensures one thread can access a critical section of code at a time, and prevents race conditions. Use MUTEX to protect shared resources.

Parallelism

Parallelism: Multiple threads can run concurrently on multi-core CPUs.

Classic Problems

Producer-Consumer Problem: Bounded buffer, solved with semaphores.

Dining Philosophers Problem: Avoid deadlock with resource hierarchy or arbitrator.

Readers-Writers Problem: Ensures multiple readers can access but writers get exclusive access.

Security

Timesharing = multiple users; Multiprogramming = multiple programs.

Kernel = full access; User = restricted. Improves security.

Trap Instruction: Switches CPU from user to kernel mode for system calls.

Kernel Mode Instruction: Disable interrupts, Set clock, Change memory map.

Interrupts and Semaphores

How can an OS use interrupts to implement semaphores?

Disable interrupts, check semaphore value, block process if down(0), wake process if up(), then re-enable interrupts.