What Is an OS?
OS & The Kernel · Assembly & OS track
5 min read
In this module
What Is an Operating System?
Every time you open a file, play a song, or fire off a message, you're leaning on an operating system (OS). The OS is the layer of software wedged between the applications you use and the physical hardware inside your computer. Without it, every program would have to know precisely how to talk to your specific hard drive, display, keyboard, and network card.
The Problem the OS Solves
Picture saving a file with no OS in the picture. Your program would need to know the exact model of your storage device, which electrical signals to send, and how to wrangle raw sectors on the disk. Now picture every program on your machine doing that independently, each with its own idea of how the disk works.
The operating system provides abstraction. It hides the messy hardware details and exposes a clean, consistent interface programs can use. Your program says "save this file" — the OS figures out the hardware-specific bits.
Here's that "save this file" request travelling down the layers on a Linux machine. Only the bottom two boxes know anything about the specific SSD; the editor at the top would work unchanged on a USB stick or a network drive.
Life Without an OS
Programs that run on bare metal do exist: firmware, boot code, tiny microcontroller projects. Here's what printing hi looks like for one of them on a PC with a classic 16550-style serial port (a UART) at I/O address 0x3F8, the traditional home of COM1. The program talks to the chip's registers itself:
/* Bare metal: no OS, no libc. inb/outb are one-instruction helpers that read or write an x86 I/O port. */#define COM1 0x3F8#define LSR (COM1 + 5) /* line status register */#define THRE 0x20 /* bit 5: transmit holding register empty */
void put_char(char c) { while ((inb(LSR) & THRE) == 0) ; /* spin until the UART can take another byte */ outb(COM1, c); /* writing to offset 0 sends the byte */}
put_char('h');put_char('i');Step by step, for the h: the program reads port 0x3FD and gets back, say, 0x60. Bit 5 is set, so the UART's transmit register is empty. It writes 0x68 (ASCII h) to port 0x3F8, and the chip starts clocking those eight bits out of the serial line. For the i, the first read might return 0x00 because the UART is still busy, so the loop spins until bit 5 comes back. That works, but only on hardware with that exact chip at that exact address.
On Linux the same job is write(1, "hi", 2). That one line holds the three things the OS adds:
- Abstraction: file descriptor 1 might be a serial port, a terminal window, a file or a pipe into another program. Your code doesn't change.
- Multiplexing: many programs can share one screen, one disk and one CPU, and the OS decides whose turn it is.
- Protection: an ordinary program isn't allowed to run
outbat all. Only the kernel touches the hardware, so a buggy program can't wreck the device for everyone else. User vs. Kernel Space shows how the CPU enforces that.
Predict: two bare-metal programs share that UART with no OS, and both start printing at the same moment, one hello and the other world. What comes out of the serial line?
Very likely a mix such as hweolrllod. Each program only checks whether the UART is ready for a byte, not whose byte came last, so their characters interleave in whatever order the timing happens to produce. Run it again and you'd get a different mess. An OS avoids this by owning the device: both programs hand their text to the kernel, which can queue each write and keep one program's bytes together.
The OS acts as a resource manager. It decides which program gets the CPU right now, how memory is carved up among running applications, and which program gets access to the disk or network at any given moment. It keeps things fair and stops programs from trampling on each other.
What the OS Provides
An operating system handles several core responsibilities:
- Process management - deciding which programs run and when
- Memory management - giving each program its own space in RAM
- File systems - organising data on storage devices
- Device management - communicating with hardware through drivers
- Security and access control - keeping programs isolated from each other
Examples of Operating Systems
You've almost certainly used at least one of these: Linux, Windows, macOS. Mobile devices run Android (built on Linux) or iOS. Servers, routers, and embedded devices have operating systems too, though they're often stripped down to the bare essentials.
People use "operating system" loosely, so it helps to pin three words down. The kernel is the privileged core that manages the CPU, memory and devices; the next lesson covers it. The operating system is the kernel plus the basic user-space pieces programs rely on: the C library, a shell, system services. A distribution such as Ubuntu or Fedora is one particular bundle of the Linux kernel, those user-space tools and a package manager. Android runs the Linux kernel too, but with its own C library (Bionic) and a very different user space, which is why an Ubuntu binary won't just run on a phone.
Look and feel aside, all operating systems share the same fundamental job: managing hardware resources and giving programs a clean interface to work against.