Why an operating system

Programs would have to know every device, and take turns

WITHOUT AN OPERATING SYSTEMBrowserWord processorGameScreenPrinterDriveWITH ONEBrowserWord processorGameScreenPrinterDriveOperatingsystemWithout an operating system, every program would need to know every device, and only one could run at a time.The operating system sits in the middle. Programs ask it for what they need, and it alone deals with the hardware.So a program written once works with any printer, and many programs can share one machine without colliding.

The operating system sits between programs and hardware, so programs share one machine safely.

The kernel

Programs never touch hardware. They ask the kernel.

Programsuser modeKernelkernel modeHardwareBrowserWord processor: SaveMusic playerProcesseswho runsMemorywho gets whatFile systemnames to blocksDriversone per deviceNetworkpacketsProcessorMemoryScreenSSDNetwork cardsystem call: writePrograms never touch hardware. They ask the kernel, and the kernel does the work.The request is a system call: the only door between a program and the machine. Behind it the kernel checksthe request, then carries it out. This is what lets many programs share one computer without trusting each other.

A program makes a system call. The kernel checks it and does the work.

Processes

A process is a program that is running

A programa file on the drivethat just sits thereyou open itRUNNING NOW: PROCESSESmemory usedBrowser620 MBWord processor180 MBMail150 MBand dozens more that the systemstarted by itselfAn example list.See your own listWindowsTask Manager (Ctrl + Shift + Esc)macOSActivity MonitorLinuxthe top commandA program is a file on the drive. A process is that program running: loaded into memory and given processor time.Open the same program twice and you get two processes. Close the window and its process ends.Most processes on the list are ones you never started. They are services, which the operating system runs in the background.

A program is a file. A process is that program running in memory. Your machine has a list of them.

Processes

One core runs one process at a time

One processor core over 60 milliseconds: who holds itBrowser36 msMusic player8 msBackup16 mswaiting for the drive0102030405060msOne core runs one process at a time, and switches every few milliseconds.The scheduler decides who runs next. A process waiting for the drive or the network gives up its turn, whichis why music keeps playing during a heavy copy. More cores means more rows running at once. Task Manageron Windows, and top or ps on Linux, list every process with its ID and its share of the processor.

The scheduler shares each core in slices of a few milliseconds.

Processes · Going deeper

Processes, threads and services

Processa running program, with its own memory and a process ID (PID)Threadone line of work inside a process; threads share the process's memoryServicea process with no window, usually started with the system (a daemon on Linux)Prioritya hint to the scheduler about who should run firstNot respondinga process stuck waiting; end it from Task Manager, or with taskkill or killStart-up appsprograms launched at sign-in; each one lengthens the waitTask Manager answers "what is running, and what is it using?".Its tabs show processes, performance, start-up apps, users and services. On Linux the same answers comefrom ps, top and systemctl. A processor held at 100% by one process is a fault in that program, not the machine.

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

Browser: its own pagesEditor: its own pagesReal memoryPage file on the driveframe 0frame 1frame 2frame 3frame 4frame 5browser page 2editor page 3page 0page 1page 2page 3page 0page 1page 2page 3Each process sees private memory. The kernel maps it, page by page, onto the real thing.Pages are 4 KB, so 16 GB of memory is 4,194,304 of them. A process cannot name another's pages, so it cannotread or damage them. When memory fills, pages not used lately move to the page file (swap on Linux) andcome back when touched. That is slow, and it is why a machine short of memory grinds.

The kernel maps each process's pages onto real memory, or onto the page file.

Files and folders

Files live in folders, and a path leads to each one

UsersdanaDocumentsreport.docxPictures, Downloads and moreWindowsC:\Users\dana\Documents\report.docxLinux/home/dana/Documents/report.docxthe path: the route from the top down to one fileA file is a named piece of data. A folder holds files and other folders. A path is the route down to one file.This tidy tree is something the operating system shows you. On the drive there are only numbered blocks, as lesson 4 showed.Go deeper to see how the operating system turns a name into the right blocks.

A file is named data, a folder holds files and folders, and a path is the route to one file.

Files and folders · Going deeper · 1 of 2

Under the folders: a file system turns a name into blocks

/home/ana/report.txtDirectory /entry: homeDirectory homeentry: anaDirectory anaentry: report.txtFile recordsize 10,240 bytesowner anapermissions rw-r--r--modified 14 Nov 09:12blocks 8812 to 8814On the driveblock 8812block 8813block 8814A file system turns a name into a list of numbered blocks.The drive stores only blocks, here 4 KB each. This 10 KB file needs 3 of them, so it takes 12 KB on the drive.Its name lives in the directory; everything else lives in the file record: an inode on Linux, an entry inthe Master File Table on NTFS. Deleting a file removes the entry. The blocks stay until they are reused.

The directory holds the name. The file record holds everything else, including the blocks.

Files and folders · Going deeper · 2 of 2

The file systems you will meet

File systemUsed onLargest fileKnown forNTFSWindows system drivesno practical limitpermissions, encryption, compressionReFSWindows Server storageno practical limitdetects and repairs corruptionFAT32old USB sticks, the EFI partition4 GBread by everything; no permissionsexFATUSB sticks and SD cardsno practical limitread by Windows, macOS and Linuxext4Linux16 TBpermissions, journalXFSLinux serversno practical limitvery large files and volumesAPFSmacOS and iOSno practical limitsnapshots, encryptionA 5 GB video will not copy to a FAT32 stick: its files stop at 4 GB.For a drive that moves between Windows, macOS and Linux, format it as exFAT. A system drive uses its ownsystem's native format, because only that one stores the permissions the system relies on.

NTFS on Windows, ext4 on Linux, APFS on Apple, exFAT for drives that travel.

Drivers

A driver teaches the kernel one device

User modeprogramsKernel modefull accessBrowserSpreadsheetGamecrashes: only the game stopsKernelgeneric requestsStoragedriverSSDGraphicsdriverGraphics cardPrinterdriverPrinterNetworkdriverNetwork carda fault here stops the whole systemA driver teaches the kernel one device, and runs with the kernel's full access.The kernel asks every drive to "write this block"; each driver turns that into its own device's commands.No driver, no device: it shows in Device Manager with a warning mark. A faulty program is stopped alone. Afaulty driver stops everything, which is why a blue screen so often follows a driver update.

Drivers run in kernel mode. A faulty program stops alone; a faulty driver stops everything.

Users and permissions

Every request is checked against who is asking

Text editorrunning as anaopenKernelcompares user with file✓/home/ana/report.txtowner ana · rw- r-- r--✗/etc/shadowowner root · rw- --- ---Every request carries a user, and the kernel checks it against the file before acting.A program has exactly the rights of the account that started it. Administrator on Windows and root on Linuxpass every check, which is why daily work is done as a standard user. A User Account Control prompt, orsudo on Linux, raises rights for one task only.

A program has the rights of its user. The kernel checks each request against the file's permissions.

Users and permissions · Going deeper

Reading permissions

Linux: three letters each for owner, group and everyone elseOwnerrwx4 + 2 + 1 = 7Groupr-x4 + 0 + 1 = 5Everyone elser--4 + 0 + 0 = 4r = read (4), w = write (2), x = run (1). This file is mode 754.Windows (NTFS): levels granted to users and groupsReadopen and viewRead & executealso run programsWritecreate and changeModifyalso deleteFull controlalso change the permissionsBoth systems answer the same question: who may do what to this file?On NTFS a folder passes its permissions down to what it holds, and an explicit Deny beats an Allow. Giverights to groups, not to people, and give the least that lets the work be done.

Linux: rwx for owner, group and everyone else. Windows: levels from Read to Full control.

The five jobs

An operating system does five jobs

Programs: the browser, the word processor, mailTHE OPERATING SYSTEMRuns programsprocessesShares out memoryprivate to each processKeeps filesnames, folders, blocksTalks to devicesthrough driversChecks who is askingusers and permissionsHardware: processor, memory, storage, screen, printerAn operating system does five jobs, and every one puts it between the programs and the hardware.Windows, Linux and macOS all do the same five. They differ in names and tools, which lesson 8 sets side by side.All of this lives on the drive. Lesson 7 follows how it gets into memory when you press the power button.

It runs processes, shares memory, keeps files, talks to devices and checks permissions.

Lesson complete

You finished “What an operating system does”

Nicely done.

Open in a new tab