Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 55 ยท Operating Systems

What an Operating System Does

Learn what an operating system does: the kernel, user space, drivers and system calls, shells and GUIs, Windows, macOS, Linux and Android, and how a computer boots.

Imagine ten programs all wanting the screen, the keyboard, the disk and the processor at the same moment. Without a referee they would overwrite each other's data, fight over devices and crash the whole machine whenever one of them misbehaved. The operating system (OS) is that referee. It is the main piece of system software: it manages the hardware, shares it fairly between programs, protects them from each other and gives them a simple set of services to build on.

This lesson opens the Operating Systems chapter. It explains the parts of an OS, how a program asks for help through system calls, the most common operating systems, and what happens between pressing the power button and seeing a desktop. It builds on Hardware and Software.

The jobs of an operating system

An OS does five big jobs, each of which has its own lesson later in this chapter:

  1. Process management: start programs, switch between them quickly and stop them. See Processes, Threads and Scheduling.
  2. Memory management: give each program its own private slice of memory. See Memory Management.
  3. File systems: turn raw storage into named files and folders. See File Systems.
  4. Device management: talk to keyboards, screens, disks and network cards through drivers.
  5. Security and users: accounts, permissions and keeping one program from reading another's data.

On top of these it provides the user interface, either a graphical desktop or a text command line.

The kernel and user space

The heart of the OS is the kernel. It is the one piece of software with complete access to the hardware. Everything else, including your browser, games, and most of the OS's own tools, runs as ordinary programs with limited rights.

Processors support this split directly with two (or more) privilege modes:

  • Kernel mode (also called supervisor mode): can execute every instruction and touch all memory and devices.
  • User mode: restricted. A program here cannot talk to the disk, change another program's memory or turn off the machine directly.

The area where ordinary programs live is called user space; the kernel's area is kernel space. If a user program crashes, the kernel notices and cleans up, and the rest of the system continues. If the kernel itself fails, the whole machine fails: a "blue screen" on Windows or a "kernel panic" on macOS and Linux.

flowchart TB
  subgraph US["User space (restricted)"]
    APP1["Browser"]
    APP2["Game"]
    APP3["Text editor"]
  end
  SC["System call interface"]
  subgraph KS["Kernel space (full privilege)"]
    K["Kernel: processes, memory, files, networking"]
    DRV["Device drivers"]
  end
  HW["Hardware: CPU, RAM, disk, network card"]
  APP1 --> SC
  APP2 --> SC
  APP3 --> SC
  SC --> K
  K --> DRV
  DRV --> HW

Programs never touch hardware; they cross the system call interface and the kernel acts on their behalf.

Drivers

A driver is code that knows how to talk to one kind of device. The kernel offers a general idea ("read these bytes from the disk"), and the driver turns it into the exact commands that one disk controller understands. Most drivers run in kernel mode, which is why a faulty driver can crash a whole system. Operating systems ship with many drivers and let hardware makers add more.

System calls: how programs ask for help

A program in user mode needs the OS for almost everything useful: opening a file, printing text, reading the clock, sending data on the network. It asks through a system call (syscall). Behind the scenes:

  1. The program places a request number and arguments in agreed registers.
  2. It runs a special instruction that switches the processor into kernel mode and jumps to a fixed kernel entry point.
  3. The kernel checks that the request is valid and allowed, does the work, and stores the result.
  4. It switches back to user mode and returns control to the program.

You rarely make syscalls yourself. Library functions such as print in Python, fopen in C or readFile in Node.js make them for you, which is why the same program works on a different kernel once the library is adapted.

On Linux you can watch the real thing with a tool called strace. This is read-only here, because the site cannot run it, and the output below is abridged and typical rather than exact:

Terminal
strace -e trace=openat,read,write cat notes.txt
# openat(AT_FDCWD, "notes.txt", O_RDONLY) = 3
# read(3, "buy milk\n", 131072)            = 9
# write(1, "buy milk\n", 9)                = 9

Even a simple cat is just a few system calls: open a file, read it and write the text to the screen (file descriptor 1). The next stand-in imitates that boundary with a dispatcher: a table from call names to kernel handlers, with a permission check.

JS A system-call dispatcher

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The important lesson is the shape: every request passes through one checked doorway, so the kernel can refuse what is not allowed. The stand-in uses ordinary function calls; in a real system the doorway is a hardware mode switch that user code cannot bypass.

Shell and graphical interface

The shell is the program that lets you give commands to the OS. A command-line shell (Bash, PowerShell, zsh) takes typed commands. A graphical user interface (GUI) uses windows, icons and a pointer. Both are ordinary user-space programs that call the kernel through system calls, which is why you can replace one with another without changing the kernel. You will practise the first in The Command Line: First Steps.

The major operating systems

OS Typical devices Notes
Windows PCs, laptops, some servers Most widely used on desktop PCs; kernel called NT
macOS Apple desktops and laptops Built on a Unix-style foundation
Linux Servers, cloud, embedded devices, desktops Open source; many distributions (Ubuntu, Fedora, Debian) share the Linux kernel
Android Most phones and tablets Uses the Linux kernel plus its own user layer
iOS / iPadOS Apple phones and tablets Closely related to macOS internals

Many of these share Unix ideas (files as streams, small tools, a text shell), which is why skills carry across macOS, Linux and Android's underlying system. Servers on the internet mostly run Linux. Smaller embedded operating systems run inside routers, cars and appliances.

How a computer boots

When you press the power button, memory is empty and no OS is running. Booting bootstraps the machine up in stages:

flowchart LR
  P["Power on"] --> F["Firmware<br/>UEFI or BIOS"]
  F --> T["Hardware self-test"]
  T --> BL["Boot loader<br/>found on storage"]
  BL --> K["Kernel loaded<br/>into RAM"]
  K --> S["Drivers and system services start"]
  S --> L["Login screen or desktop"]

Each stage is just enough software to load the next, larger one.

  1. The processor starts by running firmware from a chip on the motherboard, which tests the hardware.
  2. Firmware finds a boot loader on the storage device and runs it.
  3. The boot loader loads the kernel into RAM and starts it.
  4. The kernel initialises memory and drivers, then starts the first user-space program, which launches the rest of the system services.
  5. Finally you see a login screen or desktop.
JS A boot sequence in stages

Press Run (or Ctrl + Enter) to see the console output here.

No output.

If a computer fails early in this chain, the symptoms differ: no display and no beeps points at hardware or firmware, "operating system not found" at the boot loader or storage, and crashes during start-up at drivers or system services. Troubleshooting, Performance and Upgrades builds on this.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the kernel?

    The kernel is the privileged core of the OS. Other software runs in user space with limited rights.
  2. 2. Why can a normal program not talk to the disk directly?

    Privilege modes keep programs from touching hardware, so the kernel can share devices safely and enforce permissions.
  3. 3. What is a system call?

    System calls are the controlled doorway between user space and the kernel.
  4. 4. Which stage of booting comes directly before the kernel is loaded?

    Firmware starts the boot loader, and the boot loader loads the kernel into RAM.
  5. 5. Which statement about Android is accurate?

    Android's foundation is the Linux kernel, with a different set of libraries and apps on top.

Summary

  • The operating system shares hardware between programs, protects them from each other and offers services.
  • Its jobs are process, memory, file and device management, plus security and a user interface.
  • The kernel runs in privileged mode; applications run in restricted user mode.
  • Drivers adapt the kernel's general requests to specific devices.
  • Programs ask the kernel for help through system calls, a single checked doorway.
  • Windows, macOS, Linux, Android and iOS are the main systems, many sharing Unix ideas.
  • Booting loads progressively larger pieces of software: firmware, boot loader, kernel, services and desktop.

Next: how the OS runs many programs on few processors in Processes, Threads and Scheduling.