Your phone is playing music, downloading an app update and showing WhatsApp messages, all at the same moment. It has one screen, one battery and a limited amount of memory. How can many programs share one machine without wrecking each other? The answer is the operating system (OS), the software this whole course is about.
The problem an operating system solves
A computer is a collection of hardware: a processor (CPU), memory (RAM), disks, a screen, a keyboard, a network card. Each device has its own awkward rules. If every program talked to the hardware directly, each programmer would need to know every device, and two programs using the same device would clash.
The operating system is the software that sits between programs and hardware. It does two jobs.
- It manages resources. CPU time, memory space, disk space and devices are all resources. The OS decides which program gets which resource and for how long, and takes it back when needed. It tries to be fair and to keep the hardware busy.
- It hides complexity. An abstraction is a simple idea that hides messy details. You think in files and folders; the OS turns them into blocks on a disk. You think “show this window”; the OS drives the graphics hardware.
Think of a station master at a busy railway station. Trains (programs) want platforms (resources), and the station master decides who uses which platform and when, so two trains never meet on one track. The OS plays this role for programs.
Kernel, user mode and system calls
The kernel is the core of the operating system. It is loaded when the computer starts, stays in memory all the time and has complete control of the hardware. Around it sit system programs, libraries and the shell, the part you use to give commands, by typing or by clicking.
If every program could do anything to the hardware, one buggy app could crash the whole machine or read another person’s data. So the CPU works in two modes:
- In user mode a program can run ordinary instructions only. All apps run here.
- In kernel mode (also called privileged or supervisor mode) every instruction is allowed. Only the kernel runs here.
Instructions such as “send data to the disk”, “change the memory map” or “halt the CPU” are privileged instructions, and the CPU refuses them in user mode. So how does an app ever save a file? It asks the kernel. That request is a system call.
What happens when you press Save
You click Save in a notes app. In outline:
- The app calls a library function such as
write. - The library executes a special instruction (a trap). The CPU switches to kernel mode and jumps to a fixed place in the kernel.
- The kernel checks that you are allowed to write this file.
- The file system picks the disk blocks, and the device driver (software that knows one particular device) tells the disk to store the data.
- The kernel returns the result and the CPU switches back to user mode.
The app never touched the disk itself. The kernel did it on its behalf, after checking.
You can make a system call yourself in C on Linux:
#include <unistd.h>
#include <string.h>
int main(void) {
const char *msg = "Hello from a system call\n";
write(1, msg, strlen(msg)); /* 1 means standard output (the screen) */
return 0;
}
It prints Hello from a system call. Functions such as printf are friendlier wrappers that end up calling write for you.
The kernel also needs a way to take control back from a program that never stops. For that, a hardware timer sends an interrupt, a signal that makes the CPU pause and run an OS routine, at regular intervals. We use this timer again in the scheduling lessons.
Kinds of operating systems and how they are built
Operating systems differ in what they are designed for.
| Type | Main idea | Where you meet it |
|---|---|---|
| Batch | Similar jobs run one after another with no user interaction | Early mainframes; overnight billing |
| Multiprogramming | Several programs stay in memory; when one waits for I/O (input or output), the CPU runs another | Keeps the CPU busy |
| Time-sharing (multitasking) | The CPU switches among programs so fast that each user feels the computer is theirs | Laptops, phones, servers |
| Real-time | Must respond within a fixed deadline: missing it is a failure in hard real-time, tolerable in soft | Airbag controllers; video playback is soft |
| Distributed | Many computers linked by a network act as one system | Large web services |
| Embedded | A small OS built into a device for one job | Routers, washing machines |
Inside, the kernel can be organised in different ways:
- Monolithic kernel: the whole OS runs in kernel mode as one large program. It is fast, but a bug in any part can crash everything. UNIX and Linux are monolithic, although Linux can load extra parts such as drivers as modules while running.
- Microkernel: only the essentials stay in the kernel; the file system and drivers run as ordinary user programs that exchange messages. It is more reliable but needs more message passing. MINIX and QNX are microkernels.
- Hybrid kernel: a mixture of the two. The Windows NT family, which includes Windows 10 and 11, is usually called hybrid.
Match the job
Which OS type fits each case: (a) a bank’s overnight interest calculation, (b) a pacemaker controller, (c) a college lab server shared by 40 students at once?
Answer: (a) batch, (b) hard real-time, (c) time-sharing.
Key points
- An operating system manages the CPU, memory, disks and devices, and hides hardware details behind simple ideas such as files and processes.
- The kernel runs in kernel mode with full power; apps run in user mode and ask the kernel for help through system calls.
- A hardware timer interrupt lets the OS take the CPU back from any program.
- Batch, time-sharing, real-time, distributed and embedded systems serve different needs.
- Monolithic, micro and hybrid kernels trade speed against reliability.