Skip to content

Introduction to Operating Systems

Operating Systems Overview

Two views of an Operating System

Application View: What services does it provide?

  • What services does it provide to protect (i.e. part cop) the system?
  • What services does it provide to facilitate using the system?

The operating system (OS) provides an execution environment for running programs, making hardware accessible to the programmer.

OS Responsibilities

  • Protection (Often):
    • The OS isolates running programs to prevent interference.
    • Example: Prevents one program's bug from crashing another.
  • Facilitation:
    • The OS provides programs with necessary resources.
    • Examples: CPU time, memory, disk storage, I/O devices (keyboard, monitor).
  • Interface Provision (Usually):
    • The OS offers interfaces for programs to access these resources.
    • This gives programs an abstract view of hardware functionality.

System View: What problems does it solve?

The OS is responsible for managing and coordinating the use of hardware among various programs.

Key Functions of the OS

  • Manages the hardware resources of the system.
  • Allocates resources to programs:
    • Example: Deciding how much RAM and CPU time each program should receive.
  • Controls access to and sharing of resources between programs.

Additional Challenge

  • The OS itself consumes resources.
  • It must share these resources with application programs, making OS design more complex.

Types of Operating Systems

Primitive OS

  • Library OS: Used in simple devices (e.g., doorbell cameras); provides only essential library of services instead of a full OS.
  • System runs one program at a time.
  • Assumes no bad users or programs (often unrealistic).

Resulting Problem: Poor Utilization

  • Hardware: Processor stays idle while waiting for I/O.
  • Human user: Must wait for each program to finish.

image.png

Multitasking OS

  • A multitasking OS can have multiple processes existing simultaneously.
  • If one process blocks (e.g., waiting for input or I/O), another process can run.

Problems with Ill-Behaved Processes:

  • Can enter an infinite loop, never giving up the CPU.
  • Can overwrite another process's memory, causing crashes.

A multitasking OS must implement mechanisms to prevent and handle such issues.

image.png

Operating System vs. the Kernel

The kernel is the core part of the operating system that stays active from boot-up to shutdown. It handles communication between applications and hardware by responding to system calls, interrupts, and exceptions.

  • A system call allows a user program to interact with the OS.
  • Interrupts and exceptions are how the hardware interacts with the OS.
    • Interrupts: Triggered by external hardware (e.g., keyboard, mouse, timer, I/O devices).
      • Example: A keyboard sends an interrupt when a key is pressed, so the OS can read the input.
    • Exceptions: Triggered by the CPU itself during instruction execution.
      • Example: Divide by zero, invalid memory access, system calls.

The operating system includes the kernel and other components that provide services to applications, such as:

  • Utility programs (e.g., disk defragmenter, task manager)
  • Command interpreters (e.g., cmd.exe in Windows, bash in Linux)
  • Programming libraries (e.g., POSIX threads in Linux)

Providing Protection

User Space includes all programs that run outside the kernel—essentially everything a user interacts with, excluding the operating system. These programs cannot access hardware directly.

Kernel Space is the memory area where the kernel operates.

Crossing between user space and kernel space (e.g., making a system call) is expensive in terms of performance.

image.png

Multi-user OS

A multi-user operating system must offer protection to handle untrusted users or buggy applications.

Even with multiple users, the system doesn't slow down proportionally because user activity is often bursty (e.g., typing, reading, selecting).

  • “bursty” means that users don’t use the CPU continuously—they generate short, intense periods of activity followed by idle or low-demand periods

Potential issues include:

  • Excessive use of CPU, memory, or storage by users.
  • Requires management routines to share and control resource usage effectively.

image.png

Types of Kernels

Monolithic kernel: All OS components are inside the kernel, including device drivers and file systems.

Example: Linux.

Microkernel: Only essential parts (e.g., interprocess communication, scheduling, memory management) are in the kernel.

Other components like printer drivers run in user space.

Example: Mach.

Hybrid kernel: Combines aspects of monolithic and microkernel designs.

Example: Windows, macOS.

Real-time OS: Provides strict guarantees on response time with preemptive scheduling.

Used in systems requiring predictable timing like robotics, telephone systems, and manufacturing.

Note: Windows and macOS are real-time capable but not real-time OSs.

A monolithic kernel is faster than a microkernel.

  • Example: Printing from Chrome.
    • In a microkernel, the printer driver is in user space, requiring multiple context switches between Chrome, the kernel, and the driver.
    • In a monolithic kernel, the driver is in kernel space, so Chrome just makes one system call to the kernel which would send data directly to the printer.

A microkernel is more stable than a monolithic kernel.

  • Example: If a printer driver has a fatal bug:
    • In a monolithic kernel, the entire kernel might crash.
    • In a microkernel, only the printer driver crashes—leaving the rest of the system unaffected.