Operating Systems

Introduction to Operating Systems

Every keystroke, file open, and program launch sets off hundreds of invisible operations. The OS schedules CPU time, hands out memory, protects data, and keeps drivers from stepping on each other. Without it, the hardware is just expensive silicon. Understanding the OS makes the rest of the software stack legible.

  • **Why does Chrome eat so much memory?** Each tab is a separate process. The OS isolates them through virtual memory. One tab crashes, the others keep going. That architectural choice rests on OS guarantees.
  • **How does WhatsApp deliver messages instantly?** The OS wakes the app via push notifications, even when it looks 'closed'. None of that works without OS support.
  • **Why does Linux dominate servers?** 96% of the Top 500 supercomputers, every Android phone, most web servers. The reasons are baked into its OS architecture: stability, control, and open source.

Цели урока

  • Understand the OS role: hardware arbiter, abstraction layer for processes, security boundary
  • Distinguish OS generations: batch (1950s), time-sharing (1960s), personal (1980s), mobile (2000s)
  • Know kernel architectures: monolithic (Linux), microkernel (QNX, Mach), hybrid (Windows NT, XNU)
  • Explain user mode vs kernel mode and the trap/syscall transition mechanism
  • Identify OS responsibilities: CPU scheduling, memory management, I/O, security, IPC

What is an Operating System

**An Operating System (OS)** sits between programs and the hardware. It manages the machine's resources and exposes them through a usable API.

Operating System as an Orchestra Conductor

Picture an orchestra: violins, drums, flutes, all playing at once. No conductor, no music. **The conductor (OS)** coordinates the musicians (programs), allocates stage time, and keeps the instruments (hardware) in sync. The OS does the same for CPU, memory, and disks so programs don't trample each other.

The OS plays two key roles: 1. **Resource manager** - allocates CPU, memory, and disk among running programs 2. **Hardware abstraction** - hides hardware complexity behind a simple API

**Main functions of the OS:** - Process management (multitasking) - Memory management (virtual memory) - File system (data storage) - Device management (drivers) - Security and protection (permissions, isolation)

The OS provides **layers of abstraction**. There is no need to track where a file lives on disk, which sectors it occupies, or how to drive the read head. A call to `fopen()` and the OS handles the dirty work.

Example: Process Isolation

Run a browser and a text editor at the same time, and the OS gives each one the **illusion** of being the only program on the machine. The browser can't accidentally overwrite the editor's memory. This is **process isolation**.

Which of the functions is NOT a task of the operating system?

Evolution of Operating Systems

The history of operating systems is a long fight for **efficiency** and **usability**. We went from bare metal to modern multitasking systems in about 70 years, and the gap between then and now is enormous.

**1950s: no OS.** Programmers booked machine time (literally signed up for slots), showed up with punch cards, toggled the program in by hand using switches, ran it, and collected the output from a printer. A single run could eat an entire day.

**1960s: batch systems.** The first taste of automation. An operator stacked a deck of punch cards, and the OS loaded and ran them one after another. Between jobs the CPU sat idle, which was an expensive waste.

**Multiprogramming** was the 1960s breakthrough. While one program waits for data from a slow disk, the CPU switches to another. CPU utilization jumps to nearly 100%.

**1970s: the UNIX revolution.** Dennis Ritchie and Ken Thompson built UNIX at AT&T Bell Labs. The core ideas: - **Everything is a file** (even devices) - **Small utilities** that each do one thing well - **Pipes** for composing programs - **Multi-user mode** with isolation

**1980s: the PC era.** MS-DOS was single-user, no multitasking. Apple Lisa (1983) introduced a GUI. Windows 1.0 (1985) was a graphical shell layered on top of DOS.

From Command Line to GUI

Consider the jump from telegraph to video call. Talking to a computer used to look like sending telegrams: `COPY A: B:`, `DIR`, `DEL FILE.TXT`. The GUI (Graphical User Interface) made interaction visual: files are dragged to the trash with a mouse.

**1990s: Windows 95 and the modern era.** Preemptive multitasking (the OS reclaims the CPU from programs), 32-bit applications, plug-and-play devices. Linux (1991) by Linus Torvalds: an open-source UNIX-like system.

Why UNIX Has Survived 50+ Years

**Simplicity and modularity.** The kernel does the bare minimum: process management, memory, I/O. Everything else lives in userspace. That makes UNIX easy to port to anything from supercomputers to routers. Linux, macOS, and Android are all descendants of UNIX.

What key innovation did batch systems of the 1960s bring?

Types of Operating Systems

Operating systems are built for specific workloads. The requirements for a smartphone OS, a server OS, and a spacecraft OS differ drastically. Here are the main categories.

**Classification of OS by purpose:** 1. **Desktop OS** - Windows, macOS, Linux (Ubuntu, Fedora) 2. **Server OS** - Linux Server, Windows Server, FreeBSD 3. **Mobile OS** - Android, iOS 4. **Real-Time OS (RTOS)** - QNX, VxWorks, FreeRTOS 5. **Embedded OS** - for IoT devices, routers

**Desktop OS: priority is user experience.** Snappy GUI, multimedia support, compatibility with thousands of programs. macOS uses a hybrid kernel (XNU) that combines speed with stability.

**Server OS: priority is reliability and throughput.** Servers run 24/7 and serve thousands of clients in parallel. Linux dominates the space: 96% of the Top 500 supercomputers run on Linux. No GUI, just a command line, which saves resources.

**Mobile OS: priority is power efficiency.** A phone runs on battery, so the OS manages power aggressively: it kills background processes, throttles CPU frequency, and puts radios to sleep.

Android and Power Saving

Android moves idle apps into **Doze mode**. If the phone is stationary with the screen off, the system blocks network, alarms, and GPS for most apps. Battery savings can reach 30-40%.

**Real-Time OS (RTOS): priority is determinism.** On a general-purpose OS, a process might wait 10ms for the CPU, or it might wait 100ms - with no guarantee. An RTOS guarantees that a high-priority task runs within a **strict deadline**. Essential for medical devices, avionics, and automotive systems.

RTOS as a Swiss Watch

A general-purpose OS is like a city bus: it shows up "around 9:00", maybe late. An RTOS is a Swiss watch: the train leaves **at 9:00:00 exactly**, with millisecond precision. Rocket engine control needs that kind of predictability.

**Embedded OS for IoT.** Minimal systems for devices with very tight memory budgets (kilobytes of RAM): smart bulbs, sensors, wearables. Examples: Contiki, RIOT OS.

Why is Real-Time OS (RTOS) critical for medical equipment, but regular Linux is not suitable?

Operating System Architecture

How is an OS structured internally? There are a few common architectures: monolithic kernel, microkernel, and hybrid kernel. Each has trade-offs.

**Monolithic kernel.** The whole OS is one large program running in privileged mode. Drivers, file systems, networking, all of it lives in kernel space. Pro: **speed** (no context-switch overhead between subsystems). Con: a single buggy driver can take down the whole system (kernel panic).

Linux: a Monolithic Kernel

The Linux kernel is roughly 30 million lines of code. GPU drivers, ext4, the TCP/IP stack: all of it runs in kernel mode. One bad pointer in a driver triggers a kernel panic. But it's fast: a `read()` syscall returns in microseconds.

**Microkernel.** The kernel does only the essentials: thread scheduling, IPC (inter-process communication), and virtual memory. Drivers and file systems run in userspace as regular processes. Pro: **reliability** (a driver crash doesn't take down the kernel). Con: **slower** because of all the extra context switches.

Monolithic vs Microkernel

**Monolithic kernel:** a huge factory where everything is under one roof. Efficient, but a fire in any workshop shuts down the whole plant. **Microkernel:** a business park with separate companies. Each lives in its own building (isolated process). A fire in one tenant doesn't affect the neighbors, but communication is slower because every message must cross between buildings.

**Hybrid kernel.** A compromise between the two. Performance-critical components (GPU drivers, networking) live in kernel space; the rest sits in userspace. Examples: Windows NT, macOS (XNU).

**Linux kernel modules: flexibility on top of monolithic:** Linux is technically monolithic but supports dynamic module loading. Drivers can be loaded and unloaded without rebooting: ```bash lsmod # List loaded modules modprobe nvidia # Load the Nvidia driver rmmod old_driver # Unload an old driver ``` This provides microkernel-like flexibility at monolithic speed.

**User mode vs kernel mode.** Modern CPUs (x86, ARM) provide at least two privilege levels: - **User mode (Ring 3):** user programs. Can't touch hardware directly or run privileged I/O instructions. An attempt raises an exception. - **Kernel mode (Ring 0):** OS code. Full access to hardware, memory, and privileged instructions.

**Why does the split matter?** If any program could write directly to disk, a single bug could nuke the file system. Kernel mode provides protection: all dangerous operations go through permission checks.

Microkernel architecture is always better than monolithic because it's more reliable

Picking an architecture is a trade-off between performance and reliability. Different approaches fit different jobs

Microkernels are more reliable thanks to component isolation, but slower because of IPC overhead. Linux went monolithic + modules to get speed for desktops and servers, where performance is critical. QNX (microkernel) is used in cars, where predictability and safety matter most. There is no 'ideal' architecture, only the best one for the job at hand.

What is the main advantage of microkernel architecture over monolithic?

Key Ideas

  • **The OS sits between programs and the hardware.** It manages resources (CPU, memory, disks) and exposes them as abstractions (processes, files, sockets).
  • **OS evolution: from batch systems to multitasking.** UNIX (1970s) laid the foundations of modern systems: file abstraction, pipes, multi-user mode. Linux and macOS are direct heirs.
  • **Different OS types for different jobs.** Desktop (UX), server (reliability), mobile (power efficiency), RTOS (determinism). No single OS fits everything.
  • **Kernel architecture is a trade-off between speed and reliability.** Monolithic (Linux) is fast, but a driver crash is fatal. Microkernel (QNX) is slower but more fault-tolerant. Hybrid (Windows, macOS) tries to split the difference.

Related Topics

Operating systems sit underneath most other areas of computer science:

  • Processes and Threads — The OS creates the illusion of parallel execution on a single CPU through context switching
  • Memory Management — Virtual memory, paging, and swapping let programs 'see' more RAM than is physically installed
  • File Systems — Storage abstraction: from raw disk sectors up to the files and folders that programs actually use
  • System Programming — Writing programs that talk to the OS via system calls: fork, exec, mmap, and friends

Вопросы для размышления

  • Which kernel architecture suits an OS for a Mars rover (monolithic, microkernel, hybrid), and why?
  • Why do phones run on ARM while servers run on x86-64? How does OS architecture interact with the choice of CPU?
  • If operating systems didn't exist, what would software development actually look like day to day? Which kinds of applications simply wouldn't be feasible?

Связанные уроки

  • os-02-processes — Processes are the first key abstraction of an OS
  • arch-01-binary — Computer architecture is the physical foundation managed by the OS
  • net-01-intro — The network stack is implemented inside the OS
  • st-01-feedback-loops — The OS scheduler is a classic example of a feedback-control system
  • arch-04-cpu
Introduction to Operating Systems

0

1

Sign In