Why an operating system
Programs would have to know every device, and take turns
The operating system sits between programs and hardware, so programs share one machine safely.
Why does a computer need an operating system at all? Picture one without. Three programs, three devices. Every program would need its own code for every screen, every printer and every drive, and two programs could not run together without colliding. Put an operating system in the middle. Now each program asks the operating system, and only the operating system deals with the hardware.
The kernel
Programs never touch hardware. They ask the kernel.
A program makes a system call. The kernel checks it and does the work.
An operating system is the layer between your programs and the hardware. Follow one request down through it. You press Save in a word processor. The program cannot reach the drive, so it makes a system call, and the kernel's file system works out which blocks to write. It passes them to the driver for that drive. And the driver tells the SSD.
Processes
A process is a program that is running
A program is a file. A process is that program running in memory. Your machine has a list of them.
What is actually running on your computer right now? A program is only a file on the drive. It does nothing by sitting there. When you open it, the operating system loads it into memory and starts it. Now it is a process. The operating system keeps a list of every process and what each is using. You can see that list yourself: Task Manager on Windows, Activity Monitor on a Mac, the top command on Linux.
Processes
One core runs one process at a time
The scheduler shares each core in slices of a few milliseconds.
A process is a program that is running. Here is one processor core over sixty milliseconds. The browser holds it in six millisecond slices. Between them, the music player takes two milliseconds at a time: all it needs. A backup takes its turns too. When the backup has to wait for the drive, it gives up the core, and the others carry on.
Processes · Going deeper
Processes, threads and services
A process owns memory. A thread is a line of work inside it. A service has no window.
Memory management
Every process gets its own private memory
The kernel maps each process's pages onto real memory, or onto the page file.
Every process believes it has memory to itself. The browser sees four pages, numbered from zero. The kernel maps them onto whichever frames of real memory are free. The editor sees its own four pages, mapped to different frames. Neither can name the other's. When real memory runs short, the kernel moves pages that have not been used lately onto the drive, and brings them back when they are touched.
Files and folders
Files live in folders, and a path leads to each one
A file is named data, a folder holds files and folders, and a path is the route to one file.
Where is your report? You would say: in Documents. The operating system keeps files in folders, and folders inside folders. Users, then your own folder, then Documents, then the report. Each folder can hold many others beside it. Written out in full, that route is the path. Windows writes it with backslashes, starting from a drive letter. Linux writes it with forward slashes, starting from a single top.
Files and folders · Going deeper · 1 of 2
Under the folders: a file system turns a name into blocks
The directory holds the name. The file record holds everything else, including the blocks.
A drive knows nothing about files. It stores numbered blocks. The file system builds everything else on top. To open this path, it reads the root directory to find home, home to find ana, and ana to find the file's entry. That leads to the file record: size, owner, permissions, dates, and a list of blocks. And those three blocks on the drive hold the contents.
Files and folders · Going deeper · 2 of 2
The file systems you will meet
NTFS on Windows, ext4 on Linux, APFS on Apple, exFAT for drives that travel.
Drivers
A driver teaches the kernel one device
Drivers run in kernel mode. A faulty program stops alone; a faulty driver stops everything.
The kernel cannot know every device ever made. So it makes generic requests, and each device comes with a driver that translates them. Drivers run inside the kernel, with full access to the machine. That matters when something goes wrong. A program that crashes in user mode is stopped, and nothing else notices. A driver that faults in kernel mode takes the whole system down with it.
Users and permissions
Every request is checked against who is asking
A program has the rights of its user. The kernel checks each request against the file's permissions.
The last job of the operating system is deciding who may do what. Every process runs as a user. Here a text editor, running as ana, asks the kernel to open a file. For her own report the kernel finds that ana is the owner with read and write rights, and allows it. For the system's password file, owned by root with no rights for anyone else, it refuses.
Users and permissions · Going deeper
Reading permissions
Linux: rwx for owner, group and everyone else. Windows: levels from Read to Full control.
The five jobs
An operating system does five jobs
It runs processes, shares memory, keeps files, talks to devices and checks permissions.
Put the lesson in one picture. The operating system sits between the programs above and the hardware below, and it does five jobs. It runs programs, as processes. It shares out memory, and keeps each process to its own. It keeps files, and finds their blocks. It talks to devices, through drivers. And it checks who is asking, with users and permissions. Next: how all of this gets started.
Lesson complete
You finished “What an operating system does”
Nicely done.