Chapter 2: Operating-System Structures

Operating Systems
ServicesProcess, address space, fileDual modeSystem calls POSIX and Win32MonolithicLayeredMicrokernel ModularHybridExokernelVirtual machinesLinking and booting
Sercan KÜLCÜ · Giresun University · Computer Engineering

Introduction

Learning Outcomes

Services and concepts

Explain the services an OS provides and the concepts of process, address space, file, mounting and pipe.

System calls

Trace step by step the switch from user to kernel mode, parameter passing and the basic POSIX calls.

Kernel structures

Compare monolithic, layered, microkernel, modular, hybrid and exokernel structures, with their strengths and weaknesses.

Virtualization and booting

Describe virtual machines and containers, the linker/loader and the boot steps.

Introduction

Why Does Structure Matter?

  • An OS is made of many components: process, memory, file, I/O and network management, and more.
  • The strategy for where these components run (kernel / user mode) and how they communicate (function call / message) is called the OS structure.
  • Structure directly affects how we manage complexity, make changes, debug and port.
PerformanceReliabilityand isolationFlexibilityand maintenancetrade-off
There is no single right structure: each offers a particular trade-off and suits particular uses (desktop, server, embedded, safety-critical).

Services

Operating-System Services

Users and other system programsInterfaces:GUITouchCommand lineSystem callsOperating-system servicesProgram executionI/O operationsFile systemsCommunicationResource allocationAccountingError detectionProtection, securityHardware

User interfaces and programs reach the services through system calls (adapted from Silberschatz, Figure 2.1).

Services

Whom Do the Services Serve?

Helping users and programs
  • Interface: command line, GUI, touch, voice.
  • Program execution: load, run, terminate normally or abnormally.
  • I/O operations: a program reaches a device through the OS, not directly.
  • File system: create, delete, read, write, search, permissions.
  • Communication: shared memory or message passing (local / network).
  • Error detection: hardware, device and program errors.
Keeping the system efficient and secure
  • Resource allocation: CPU, memory and storage are shared among many processes.
  • Accounting: who used how much of what; logs.
  • Protection: processes cannot harm each other or the kernel.
  • Security: authentication, authorization, defense against outside attacks.
Most users see the OS not through system calls but through system programs: ls, cp, ps, package managers, compilers, file managers…

Basic Concepts

Process

  • A process is a program in execution; the program is a passive file on disk, the process its active instance.
  • Each process has an address space (code, data, stack), registers (PC, SP), open files, alarms, related processes and other resources.
  • The OS keeps this information in the process table; a suspended process resumes where it left off thanks to its PCB.
  • Processes can talk to each other through IPC (interprocess communication).
Process tablePIDStateProgram1sleepingsystemd812waitingbash1045runningls1046readygrepPCB (process control block)PID, state, priorityPC, SP and other registersmemory map (address space)open files (fd table)signals, alarms, UID, parent

Basic Concepts

Process Tree

A process can create child processes with fork(); the children create their own children. The result is a tree.

APID 1 (systemd) is the root of the tree

At first only process A exists. On Linux the root of the whole tree is systemd (or init), PID 1.

ABCfork()

Process A calls fork() twice: B and C are A's children (A is their parent).

ABCDEFfork()fork()

Process B creates three children: D, E and F. The pstree -p command shows this tree.

Basic Concepts

Address Space and Memory Segments

  • Address space: the set of addresses a process can use (0 … max). On x86-64 Linux user space is 128 TiB.
  • Many processes are in memory at once; the OS protects them from each other and from the kernel.
  • Text: machine code; read-only, shared by processes running the same program and by all threads.
  • Data + BSS: global and static variables. Heap: memory allocated dynamically at run time. Both are shared by the process's threads.
  • Stack: parameters, local variables, return addresses; each thread has its own stack.
  • Virtual memory allows address spaces larger than physical memory.
max0stackfreeheapBSSdatatextlocal variables,parameters,return addressesmalloc / newuninitialized globalsinitialized globalsmachine code,read-only

Basic Concepts

Files and the Directory Hierarchy

  • File: a named unit that stores data persistently (text, images, video, programs…).
  • The OS hides disk blocks and device details and offers a clean abstraction.
  • Files live in a directory tree. A path name can be absolute (/home/ali/notes.txt) or relative to the working directory (ali/notes.txt).
  • An opened file gets a small integer, the file descriptor (fd); 0, 1, 2 = stdin, stdout, stderr.
  • Special files: devices look like files. Block devices (/dev/sda, /dev/nvme0n1) and character devices (/dev/tty, serial port).
/binhomeusrdevaliaysesdattynotes.txthw.cdirectoryfiledevice

Basic Concepts

Mounting a File System

/binhomemntRoot file system (/dev/nvme0n1p2)rootabxyzUSB stick (/dev/sdb1)?

Before mounting, the file system on the USB stick is a separate tree; no path name reaches it.

/binhomemntRoot file system (/dev/nvme0n1p2)rootabxyzUSB stick (/dev/sdb1)mount /dev/sdb1 /mnt

mount attaches the root of the new file system to a mount point in the existing tree (the empty directory /mnt).

/binhomemntRoot file system (/dev/nvme0n1p2)abxyzNow a single tree:/mnt/a/x/mnt/b/z

Once mounted, the USB files are part of the hierarchy. Windows usually uses drive letters (C:, D:) instead.

Basic Concepts

The mount Command and Its Options

$ lsblk                              # list disks and partitions
$ sudo mount /dev/sdb1 /mnt          # mount sdb1 on /mnt
$ sudo mount -o ro /dev/sdb1 /mnt    # mount read-only
$ sudo mount -o remount,rw /mnt      # remount read-write
$ findmnt /mnt                       # show mount info
$ sudo umount /mnt                   # unmount
ro / rw

Mount read-only or read-write. ro is the safe choice for recovery and forensics.

/etc/fstab

File systems to mount automatically at boot are listed here (or in systemd mount units).

On the desktop

A plugged-in USB stick is mounted automatically under /run/media/… by udisks2.

/binhomemntmount/dev/sdb1 (USB)photos/, doc.pdf/mnt/doc.pdfnow reachable by path

Basic Concepts

Pipe

  • A one-way byte channel buffered in the kernel that connects two processes; they use it like a file, with read/write.
  • Anonymous: created with pipe(), between parent and child. Named (FIFO): created with mkfifo, has a name in the file system, usable by unrelated processes.
$ ls -l | grep "notes"
kernells -lstdout → fd[1]grep notesstdin ← fd[0]pipe buffer (64 KiB)write endread end

The shell first calls pipe(fd): the kernel opens a buffer with two ends (fd[0] read, fd[1] write).

kernells -lstdout → fd[1]grep notesstdin ← fd[0]pipe buffer (64 KiB)write endread end

The shell forks twice; with dup2, ls's stdout goes to the write end and grep's stdin comes from the read end.

kernells -lstdout → fd[1]grep notesstdin ← fd[0]pipe buffer (64 KiB)write endread end-rw-r--r-- … notes.txtto terminal

ls writes its listing into the pipe; grep reads it and prints only the lines containing “notes”.

kernells -lstdout → fd[1]grep notesstdin ← fd[0]pipe buffer (64 KiB)write endread endbuffer full → writer waits; empty → reader waitsEOF

Flow control is in the kernel: the writer blocks when the buffer is full, the reader when it is empty. When ls finishes and the write end closes, grep sees end of file (EOF).

Basic Concepts

Deadlock

  • If every process in a set waits for a resource held by another process in the set, none can proceed: deadlock.
  • Like cars entering an intersection from four directions and waiting for each other.
P1P2R1R2P1P2R1R2(a) Potential: requests not yet made(b) Actual: cycle P1→R2→P2→R1→P1holds

Arrow from box to process: the resource is held by that process. Arrow from process to box: the process requests it (dashed = will request later).

Protection

Protection with Dual Mode

  • The OS protects itself and processes through the hardware's user / kernel mode split: I/O, setting the timer, disabling interrupts and changing page tables are possible only in kernel mode.
  • If a privileged instruction is attempted in user mode, the hardware traps and the OS kills the process. The kernel is entered only through system calls, interrupts and exceptions.
  • x86 has rings 0–3, but Linux and Windows use only 0 and 3; ARM has EL0–EL3, with EL2 reserved for virtualization.
  • Mode separation alone is not enough: a timer is needed to take the CPU back, and an MMU to keep process memories apart.

Protection

Timer

  • Goal: stop a process from looping forever and never giving up the CPU.
  • The OS loads a value into a counter; this is a privileged instruction.
  • The counter decrements on every tick of the physical clock; at zero an interrupt fires and the OS regains control.
  • The OS preempts a process that has used up its time slice and gives the CPU to another (preemptive scheduling). The process is killed only if a CPU-time limit (e.g. RLIMIT_CPU) is exceeded.
  • Linux's periodic tick is 100–1000 Hz; tickless (NO_HZ) mode, which stops ticks when idle, saves energy.
counter3clock tick−1A runningCPU

Before running A, the OS loads 3 into the counter.

counter2clock tick−1A runningCPU

Each clock tick decrements the counter: 2.

counter1clock tick−1A runningCPU

Counter 1; A is still on the CPU.

counter0clock tick−1interrupt → OSCPUOS in control

Counter 0: timer interrupt. The CPU switches to kernel mode and the interrupt handler runs.

counter3clock tick−1B runningCPUcounter reloaded

A's slice is used up, so the scheduler picks B and reloads the counter.

System Calls

What Is a System Call?

  • The defined interface programs use to reach OS services (files, memory, processes, time, network…).
  • Requested by the application, executed in kernel mode by the kernel.
  • Programmers usually reach calls through an API, not directly: POSIX (glibc, musl), the Windows API, the Java API. The API gives portability and convenience.
  • The set of calls varies by system: Linux on x86-64 has about 370. The core ideas are shared.
  • strace (Linux), dtruss (macOS) and Process Monitor (Windows) show the calls a program makes.
Application programAPI: libc, Win32, Javasystem-call interfaceuserkernelKernel servicesHardware

System Calls

API → System-Call Interface → Kernel

user modekernel modeopen("notes.txt", O_RDONLY)system-call interfacesystem-call table0read1write2open3close……257openatopen() implementationfind file, check permissions

The application calls the open() wrapper in libc; the wrapper puts the call number in a register and executes the trap instruction.

user modekernel modeopen("notes.txt", O_RDONLY)system-call interfacesystem-call table0read1write2open3close……257openatopen() implementationfind file, check permissions

The kernel's system-call interface uses the number as an index into the system-call table (x86-64 Linux: open = 2).

user modekernel modeopen("notes.txt", O_RDONLY)system-call interfacesystem-call table0read1write2open3close……257openatopen() implementationfind file, check permissions

The pointer in the table leads to the kernel implementation: the path is resolved, permissions are checked, an open-file entry is created.

user modekernel modeopen("notes.txt", O_RDONLY)system-call interfacesystem-call table0read1write2open3close……257openatopen() implementationfind file, check permissionsreturns: fd = 3

The result (the lowest free descriptor: 3, since 0, 1, 2 are taken) returns to the user. Note: current glibc actually implements open() with openat (257).

System Calls · Step through the code

Code Trace: The System-Call Table

typedef long (*syscall_t)(long, long, long);
syscall_t table[3] = {sys_read, sys_write,
                      sys_open};
long syscall_entry(long no, long a,
                   long b, long c) {
  if (no < 0 || no >= 3)
    return -ENOSYS;     /* bad number */
  return table[no](a, b, c);
}
user modewrite(1, "abc", 3)kernel moderax1table[ ]0sys_read1sys_write2sys_open

The libc wrapper puts the call number in rax and executes syscall. The hardware enters kernel mode and jumps to the single entry point: no = 1 (write on Linux x86-64).

user modewrite(1, "abc", 3)kernel moderax1table[ ]0sys_read1sys_write2sys_open

0 ≤ 1 < 3: the number is valid.

user modewrite(1, "abc", 3)kernel moderax1return3table[ ]0sys_read1sys_write2sys_open

table[1] is a function pointer: sys_write is called and returns 3, the number of bytes written.

user modeopen("notes.txt", 0)kernel moderax2table[ ]0sys_read1sys_write2sys_open

A new call: open("notes.txt", 0), no = 2.

user modeopen("notes.txt", 0)kernel moderax2table[ ]0sys_read1sys_write2sys_open

0 ≤ 2 < 3: the number is valid.

user modeopen("notes.txt", 0)kernel moderax2return3table[ ]0sys_read1sys_write2sys_open

table[2] is a function pointer: sys_open is called and returns 3, the new descriptor.

user modesyscall(99)kernel moderax99table[ ]0sys_read1sys_write2sys_open

A new call: syscall(99), no = 99.

user modesyscall(99)kernel moderax99return-38table[ ]0sys_read1sys_write2sys_openno ≥ 3: not in the table

The number is outside the table. Without the check, table[99] would jump to a random kernel address. The call is rejected with −ENOSYS (−38).

user modesyscall(99) → -1kernel moderax?return-1table[ ]0sys_read1sys_write2sys_open

libc turns the negative value into errno = ENOSYS and returns −1 to the program. The kernel never uses a value from user space without validating it.

System Calls

Example: Copying One File to Another

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

Even getting a name from the user takes two calls: write a prompt to the screen (write), read from the keyboard (read).

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

The same is repeated for the output file.

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

If open fails (no such file, no permission) it returns −1; the program prints an error and exits.

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

open(…, O_WRONLY | O_CREAT | O_EXCL): fails if the file already exists.

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

The real work: a read/write loop until read returns 0 (end of file).

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

Every open file is closed with close.

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

The user is informed.

Prompt for and read the input file namewrite, readPrompt for and read the output file namewrite, readOpen the input file (if missing, report and exit)openCreate the output file (if it exists, report and exit)open + O_CREATLoop: read from input, write to outputread, writeClose the filesclosePrint “done” on the screenwriteTerminate normallyexit

The process ends with exit. Even a simple program like this makes dozens of calls; count them with strace -c cp a b.

System Calls · Step through the code

Code Trace: Copying with read/write

char buf[4096];
int in = open("src", O_RDONLY);
int out = creat("dst", 0644);
ssize_t n;  long total = 0;
while ((n = read(in, buf, 4096)) > 0) {
  write(out, buf, n);
  total += n;
}
close(in);  close(out);
printf("%ld bytes\n", total);
srcoffset 0buffree4096-byte bufferdstcalls: open×1

“src” is a 10,000-byte file. open returns the lowest free descriptor: 0, 1, 2 are taken, so in = 3; offset 0.

srcoffset 0buffree4096-byte bufferdstcalls: open×1 creat×1

An empty destination file is created: out = 4.

srcoffset 4096buf4096 bytes4096-byte bufferdstcalls: open×1 creat×1 read×1

read enters the kernel and asks for at most 4096 bytes: n = 4096. The kernel advances the file offset by 4096.

srcoffset 4096buf4096 bytes4096-byte bufferdstcalls: open×1 creat×1 read×1 write×1

The n bytes in the buffer (as many as were read, not 4096) are written to the destination.

srcoffset 4096buf4096 bytes4096-byte bufferdstcalls: open×1 creat×1 read×1 write×1

total = 4096. Each iteration costs two system calls: one read, one write.

srcoffset 8192buf4096 bytes4096-byte bufferdstcalls: open×1 creat×1 read×2 write×1

read again: n = 4096, offset 8192.

srcoffset 8192buf4096 bytes4096-byte bufferdstcalls: open×1 creat×1 read×2 write×2

4096 bytes are written, total = 8192.

srcoffset 10000buf1808 bytes4096-byte bufferdstcalls: open×1 creat×1 read×3 write×2

Only 10,000 − 8192 = 1808 bytes are left: read returns fewer than requested, n = 1808. This is not an error.

srcoffset 10000buf1808 bytes4096-byte bufferdstcalls: open×1 creat×1 read×3 write×3

1808 bytes are written, total = 10000.

srcoffset 10000buffree4096-byte bufferdstcalls: open×1 creat×1 read×4 write×3

The offset is at end of file: read returns 0 (EOF). The condition is false and the loop ends.

srcbuffree4096-byte bufferdstcalls: open×1 creat×1 read×4 write×3 close×2

Both descriptors are closed; 3 and 4 can be reused.

srcbuffree4096-byte bufferdstcalls: open×1 creat×1 read×4 write×3 close×2 +write

Output: 10000 bytes. 12 system calls in all (printf also does a write). With a 1-byte buffer, reading and writing alone would take about 20,000 calls.

System Calls

The 11 Steps of read(fd, buffer, nbytes)

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdDispatchertable[no]sys_read(handler)123

1–3: Parameters are pushed on the stack (the historical 32-bit x86 convention in Tanenbaum's example). On x86-64 the first six parameters go in registers.

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdreturn addr.Dispatchertable[no]sys_read(handler)4

4: The library's read() is called like an ordinary function; the return address goes on the stack.

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdreturn addr.Dispatchertable[no]sys_read(handler)5

5: The library puts the call number in the register the kernel expects (Linux x86-64: rax = 0).

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdreturn addr.Dispatchertable[no]sys_read(handler)6

6: The trap instruction (x86-64: syscall) runs; the CPU enters kernel mode and jumps to a fixed kernel address.

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdreturn addr.Dispatchertable[no]sys_read(handler)7

7: The kernel looks at the call number and dispatches to the right handler through the system-call table.

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdreturn addr.Dispatchertable[no]sys_read(handler)8

8: The handler copies up to nbytes bytes from fd into buffer. If no data is ready, the process blocks and the CPU goes to another process.

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdreturn addr.Dispatchertable[no]sys_read(handler)9

9: When done, control returns to user mode at the instruction after the trap; the result (bytes read) is in a register.

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stacknbytes&bufferfdDispatchertable[no]sys_read(handler)10

10: The library's read() returns to the user program.

user spacekernel spaceUser programpush nbytespush &bufferpush fdcall readclean up stackLibrary: read()call no. → registerTRAP (enter kernel)return to callerUser stackDispatchertable[no]sys_read(handler)11

11: The program pops the parameters off the stack (SP is incremented) and continues with the next instruction.

System Calls

Passing Parameters to System Calls

  1. Registers: the fastest way; Linux passes up to 6 parameters like this.
  2. Block / table in memory: parameters in memory, their address in a register (figure). E.g. clone3(struct clone_args *).
  3. Stack: the program pushes the parameters, the OS pops them.
user programload address Xinto register;system call 13X: tableparam 1param 2param 3register: Xcall 13: use the table at X
x86-64 LinuxRole
raxcall number; result on return
rdi, rsi, rdx1st, 2nd, 3rd parameter
r10, r8, r94th, 5th, 6th parameter (r10 instead of rcx from the C convention)
syscallenter kernel; rcx and r11 clobbered
ARM64x8 = number, x0–x5 parameters, svc #0
On error the kernel returns a value between −1 and −4095 (−errno); libc stores it in errno and returns −1 to the caller.

System Calls

Code Trace: Writing to the Screen with write()

#include <unistd.h>      // write()
#include <string.h>      // strlen()

int main(void) {
    const char *msg = "Hello, Türkiye!\n";
    size_t len = strlen(msg);        // 17 bytes
    ssize_t n = write(1, msg, len);  // 1: stdout
    if (n == -1)
        return 1;                    // error
    return 0;
}

msg points to the string in the read-only data segment.

“Hello, ” 7 + “Türkiye” 8 (ü takes 2 bytes in UTF-8) + “!” and “\n” 2 = 17 bytes. A hard-coded 15 would cut the output to “Hello, Türkiye”.

The libc wrapper: rax=1 (write), rdi=1, rsi=msg, rdx=17; then syscall.

In kernel mode, sys_write passes the 17 bytes to the terminal behind fd 1.

Back in user mode: n = 17, the number of bytes written. It could be smaller (a partial write).

n is not −1, so no error. On error it would be −1 and errno would be set.

main returns 0; libc ends the process with exit_group(0).

System Calls

Code Trace: read() and Blocking

#include <unistd.h>
#include <stdio.h>

int main(void) {
    char buf[100];
    ssize_t n = read(0, buf, sizeof(buf));
    if (n == -1) {
        perror("read error");
        return 1;
    }
    write(1, buf, n);    // exactly n bytes
    return 0;
}

buf is allocated on the stack; its contents are uninitialized.

fd 0 = stdin (keyboard). No line yet: the process blocks and the scheduler runs another process.

The user types “hello” and presses Enter; the terminal driver echoes the characters and buffers the line.

Once the line is complete, 6 bytes are copied into buf, the process wakes up and read returns 6. No '\0' is appended.

n = 6, no error; perror is skipped.

write outputs exactly 6 bytes. Since buf is not a C string, printf("%s", buf) would be wrong.

The program exits with 0.

System Calls

The Standard C Library and System Calls

user modekernel modeint main(void) { printf("Welcome\n"); return 0;}Standard C libraryprintf: format, put in stdoutbuffer; call write when neededwrite(1, buffer, 8) system callterminal: Welcome

The program calls printf; it is not a system call but a library function running in user mode.

user modekernel modeint main(void) { printf("Welcome\n"); return 0;}Standard C libraryprintf: format, put in stdoutbuffer; call write when neededwrite(1, buffer, 8) system callterminal: Welcome

libc formats the text and puts it in the stdout buffer. On a terminal the buffer is line-buffered; redirected to a file or pipe it is fully buffered.

user modekernel modeint main(void) { printf("Welcome\n"); return 0;}Standard C libraryprintf: format, put in stdoutbuffer; call write when neededwrite(1, buffer, 8) system callterminal: Welcome

Because “\n” arrived, libc makes the system call write(1, buffer, 8); the kernel passes the bytes to the terminal.

user modekernel modeint main(void) { printf("Welcome\n"); return 0;}Standard C libraryprintf: format, put in stdoutbuffer; call write when neededwrite(1, buffer, 8) system callterminal: Welcomereturns: 8

write returns 8 and printf returns to its caller. strace ./welcome shows only write, not printf.

Headers: stdio.h (printf, fopen), stdlib.h (malloc, exit), string.h (strlen, memcpy), math.h, time.h; POSIX unistd.h (fork, read, write). Implementations: glibc, musl, UCRT on Windows. Functions like strlen live entirely in the library; ones like write wrap a system call.

System Calls

Types of System Calls

Process control

create, terminate, load, wait, signal

fork, execve, exit, waitpid, kill
File management

create, delete, open, close, read, write, attributes

open, read, write, close, stat
Device management

request / release device, read, write, control

ioctl, read, write, mmap
Information maintenance

time, date, system and process information

getpid, uname, clock_gettime
Communications

connect, send/receive messages, shared memory

pipe, socket, sendmsg, shm_open
Protection

get / set permissions, user identity

chmod, chown, umask, setuid

Windows equivalents: CreateProcess, ReadFile, DeviceIoControl, GetSystemTime, CreatePipe, SetFileSecurity… (Silberschatz, Figure 2.8)

System Calls

POSIX Calls: Process Management

CallDescription
pid = fork()Creates a child process that is a copy of the parent.
pid = waitpid(pid, &statloc, options)Waits for a child to terminate; writes its exit status to statloc.
s = execve(name, argv, envp)Replaces the process's memory image with a new program; does not return on success.
exit(status)Terminates the process and passes the status to the parent.
parentchildwaitpid: blockedfork()copyexecve()new program (same PID)exit(status)waitpid returns with status
On error the calls return −1 and set errno. pid: process ID, s: return code. On Windows a single CreateProcess call does the work of fork + execve.

System Calls

Code Trace: A Simple Shell

#define TRUE 1

while (TRUE) {              /* forever */
    type_prompt();          /* show prompt */
    read_command(command, parameters);

    if (fork() != 0) {      /* parent */
        waitpid(-1, &status, 0);
    } else {                /* child */
        execve(command, parameters, 0);
        perror("execve");   /* on failure */
        _exit(127);
    }
}

The shell prints a prompt and waits for the user.

The user types ls; the command and its parameters are parsed.

fork makes a copy of the shell. In the parent the result is 1045 (≠ 0); in the child it is 0.

The parent waits for any child to finish with waitpid(-1, …); it blocks.

The child replaces itself with the ls program via execve (the PID stays the same); ls prints its output. Real shells search PATH for the command.

ls finishes with exit(0); the parent's waitpid returns and status holds the exit status.

The loop starts over and a new prompt is printed.

System Calls

POSIX Calls: File Management

CallDescription
fd = open(file, how, …)Opens a file for reading, writing or both (creating it if needed).
s = close(fd)Closes an open file.
n = read(fd, buffer, nbytes)Reads up to nbytes bytes from the file into the buffer.
n = write(fd, buffer, nbytes)Writes data from the buffer to the file.
position = lseek(fd, offset, whence)Moves the file position pointer (SEEK_SET, SEEK_CUR, SEEK_END).
s = stat(name, &buf)Gets the file's status information (size, permissions, times).
read so far0end of fileposition (advances with each read/write)lseek

fd: file descriptor, n: byte count, position: offset from the start of the file. Current Linux also offers openat, pread/pwrite, statx.

System Calls

POSIX Calls: Directory Management and Others

CallDescription
s = mkdir(name, mode)Creates a new directory.
s = rmdir(name)Removes an empty directory.
s = link(name1, name2)Creates a new directory entry name2 pointing to the file name1 refers to.
s = unlink(name)Removes a directory entry.
s = mount(special, name, flag)Mounts a file system (Linux: mount(src, target, type, flags, data)).
s = umount(special)Unmounts a file system.
s = chdir(dirname)Changes the working directory.
s = chmod(name, mode)Changes a file's protection (permission) bits.
s = kill(pid, signal)Sends a signal to a process (not only to kill it).
seconds = time(&seconds)Seconds elapsed since 1 January 1970 00:00 UTC (the Unix epoch).

A 32-bit time_t overflows on 19 January 2038 (the year-2038 problem); current systems use a 64-bit time_t.

System Calls

link and unlink: One File, Two Names

In UNIX a directory is a table of (i-node number, name) pairs. The file's real information lives in the i-node (inode).

/usr/ast16mail81games40test/usr/jim31bin70memo59f.c.38prog1i-node 70 (file)link count: 1

Start: /usr/jim/memo refers to i-node 70; link count 1.

/usr/ast16mail81games40test70note/usr/jim31bin70memo59f.c.38prog1i-node 70 (file)link count: 2

link("/usr/jim/memo", "/usr/ast/note"): a new entry referring to the same i-node (70) is added to /usr/ast. No data is copied; the count becomes 2.

/usr/ast16mail81games40test70note/usr/jim31bin59f.c.38prog1i-node 70 (file)link count: 1

unlink("/usr/jim/memo") removes only the entry; the file lives on as note. When the count reaches 0 (and no one holds it open) its blocks are freed.

System Calls · Step through the code

Code Trace: Link Count and an Open File

int fd = open("/usr/jim/memo", O_RDONLY);
link("/usr/jim/memo", "/usr/ast/note");
unlink("/usr/jim/memo");
unlink("/usr/ast/note");
n = read(fd, buf, 100);    /* still readable */
close(fd);
/usr/jim31bin70memo59f.c./usr/ast16mail81gamesi-node 70links = 1open = 0data blocks

A directory is just (i-node number, name) pairs. memo refers to i-node 70; link count 1, file size 85 bytes.

/usr/jim31bin70memo59f.c./usr/ast16mail81gamesi-node 70links = 1open = 1data blocksfd 3 → open-file entry → i-node 70

open resolves the path and opens i-node 70: fd = 3, the i-node's open count is 1.

/usr/jim31bin70memo59f.c./usr/ast16mail81games70notei-node 70links = 2open = 1data blocksfd 3 → open-file entry → i-node 70

link adds a new entry in /usr/ast referring to the same i-node. No data is copied; links = 2.

/usr/jim31bin59f.c./usr/ast16mail81games70notei-node 70links = 1open = 1data blocksfd 3 → open-file entry → i-node 70

unlink removes only the directory entry; the file lives on as note. Links = 1.

/usr/jim31bin59f.c./usr/ast16mail81gamesi-node 70links = 0open = 1data blocksfd 3 → open-file entry → i-node 70

The last name is gone too: links = 0. The file has no path any more, but since fd 3 holds it open, the i-node and blocks are not deleted.

/usr/jim31bin59f.c./usr/ast16mail81gamesi-node 70links = 0open = 1data blocksfd 3 → open-file entry → i-node 70

read goes straight to the i-node through the descriptor; no name is needed: n = 85.

/usr/jim31bin59f.c./usr/ast16mail81gamesi-node 70freedata blocks

The last descriptor is closed: links = 0 and open = 0. Only now does the kernel free the i-node and data blocks. Temporary files are deleted while open this way.

System Calls

Win32 API Equivalents of UNIX Calls

UNIXWin32
forkCreateProcess
waitpidWaitForSingleObject
execve(none: CreateProcess)
exitExitProcess
openCreateFile
closeCloseHandle
readReadFile
writeWriteFile
lseekSetFilePointerEx
statGetFileAttributesEx
UNIXWin32
mkdirCreateDirectory
rmdirRemoveDirectory
linkCreateHardLink
unlinkDeleteFile
mountSetVolumeMountPoint
umountDeleteVolumeMountPoint
chdirSetCurrentDirectory
chmod(none: ACLs, SetFileSecurity)
kill(none: TerminateProcess)
timeGetSystemTime
The Win32 API has thousands of functions; the actual kernel transition is done by the Nt… functions in ntdll.dll (e.g. NtCreateFile). Their numbers change between versions and are undocumented, so programs use the API. The link and mount equivalents listed as “none” in Tanenbaum 3e exist today.

Structures

Operating-System Structures: Overview

SimpleMS-DOSMonolithicUNIX, LinuxModularLinux LKM, SolarisHybridWindows NT, macOSMicrokernelMINIX 3, QNX, seL4ExokernelAegis / ExOS← much in kernel modevery little in kernel mode →
Layered approach

Not a placement but an organizing principle: components are split into hierarchical layers (THE, MULTICS rings).

Virtual machines

A separate axis: the hardware itself is virtualized and several OSes run on top of it.

Structures

Simple Structure: MS-DOS

Application programResident system programMS-DOS device driversROM BIOS device driverslayerbypass
  • No clear structure: it was written to be small and simple, for limited hardware.
  • Interfaces and levels of functionality are not well separated; applications can reach BIOS routines and the hardware directly.
  • The Intel 8088 had no dual mode, so there was no hardware protection: one faulty program could crash the whole system.
  • No clear boundaries between modules and no data hiding.
  • Silberschatz treats this as a “simple structure”, separate from monolithic kernels.

Structures

Monolithic Systems

The whole OS is linked as a single program running in kernel mode. Any procedure can call any other directly.

  1. Main program: looks at the call number and invokes the requested service procedure.
  2. Service procedures: carry out the system calls.
  3. Utility procedures: work shared by several services (e.g. fetching data from user memory).

Most monolithic kernels today also accept drivers and file systems as loadable modules at run time.

Main procedureserviceserviceserviceserviceutil.util.util.util.util.all one binary, one address space, kernel mode

Structures

Traditional UNIX and Linux: The Monolithic Kernel

Usersshells, commands, compilers, system librariessystem-call interfaceKernelsignals,terminal handling,character I/O,terminal driversfile system,swapping, block I/O,disk driversCPU scheduling,page replacement,virtual memorykernel–hardware interfaceterminalcontrollersdevicecontrollersmemorycontrollers

Strengths

  • Direct function calls: no IPC, no mode switches, fast.
  • Relatively simple, integrated design and implementation.

Weaknesses

  • One driver bug can crash the whole kernel.
  • A huge code base (Linux passed 40 million lines in 2025): debugging and maintenance are hard.

Structures

Layered Approach

0Processor allocation, multiprogramming

Layer 0: switches between processes on interrupts and timer expiry; layers above need not think about the single CPU.

0Processor allocation, multiprogramming1Memory and drum management

Layer 1: allocates memory to processes and moves pages between the drum (the disk of the day) and memory.

0Processor allocation, multiprogramming1Memory and drum management2Operator–process communication

Layer 2: handles communication between each process and the operator console.

0Processor allocation, multiprogramming1Memory and drum management2Operator–process communication3I/O management

Layer 3: manages I/O devices; layers above work with abstract devices.

0Processor allocation, multiprogramming1Memory and drum management2Operator–process communication3I/O management4User programs

Layer 4: user programs; they need not deal with memory, console or I/O details.

0Processor allocation, multiprogramming1Memory and drum management2Operator–process communication3I/O management4User programs5Operator

Layer 5: the system operator. Dijkstra's THE system (1968) had these six layers.

The OS is divided into layers: the bottom layer is closest to the hardware, the top to the user. Each layer uses the services of only the layers below it.

Pros

  • Debugging and verification proceed layer by layer; a bug is sought in the relevant layer.
  • Abstraction and data hiding come easily.

Cons

  • Defining the layers properly is hard (dependencies often run both ways).
  • Each layer crossing adds overhead. The idea lives on today in network stacks.

Structures

Microkernels

  • Everything nonessential is moved out of the kernel; only IPC (message passing), basic scheduling, address-space management and interrupt handling remain.
  • Drivers, file systems and the network stack run as user-mode server processes; new services are added in user space without changing the kernel.
  • Examples: Mach, MINIX 3, QNX Neutrino (automotive), the L4 family, the formally verified seL4, and the Zircon kernel of Google Fuchsia. macOS, by contrast, uses XNU, a hybrid derived from Mach.
  • Mechanism in the kernel, policy outside: the kernel can run processes by priority; a user-mode component decides how priorities are assigned.

Pros

  • A crashed driver does not bring the system down; it can be restarted.
  • Small kernel: easy to test, verify and port.
  • More secure: a small attack surface.

Cons

  • Messages and mode switches add overhead; L4 designs greatly reduced it.
MonolithicuserapplicationkernelFSdriversnetwork stackMicrokerneluserapplicationFSdriverkernelIPC, scheduling

Structures

Reading a File on a Microkernel

user modekernel modeApplication programFile systemDevice driverIPC (message passing)Memory managementCPU schedulingHardwaremessage: read(file)

The application sends a message to the file-system server; the message passes through the kernel's IPC mechanism.

user modekernel modeApplication programFile systemDevice driverIPC (message passing)Memory managementCPU schedulingHardware

The kernel delivers the message to the file-system server in user mode.

user modekernel modeApplication programFile systemDevice driverIPC (message passing)Memory managementCPU schedulingHardware

The file system works out which block to read and sends a message, again through the kernel, to the disk driver.

user modekernel modeApplication programFile systemDevice driverIPC (message passing)Memory managementCPU schedulingHardwarereply

The driver reaches the hardware through I/O the kernel permits; replies come back the same way. In a monolithic kernel this is a single chain of function calls.

Structures · Step through the code

Code Trace: send/receive on a Microkernel

/* client */
m.type = READ; m.file = 7; m.offset = 0;
send(FS, &m);
receive(FS, &m);       /* wait for reply */
/* file-system server (FS) */
while (1) {
  receive(ANY, &m);
  block = find_block(m.file, m.offset);
  send(DISK, &block);
  receive(DISK, &data);
  m.result = data;
  send(m.source, &m);
}
ClientrunningFile sys. (FS)blocked (receive)Disk driverblocked (receive)user modemicrokernel: IPC (copies the message, wakes the receiver)messages: 0m = {READ, 7, 0}

FS and the disk driver are each a user-mode process; both wait for work in receive. The client writes its request into a message structure.

Clientblocked (receive)File sys. (FS)runningDisk driverblocked (receive)user modemicrokernel: IPC (copies the message, wakes the receiver)messages: 1m → FS

send traps into the kernel: the kernel copies the message into FS's buffer and wakes FS. The client blocks in receive for the reply.

Clientblocked (receive)File sys. (FS)runningDisk driverblocked (receive)user modemicrokernel: IPC (copies the message, wakes the receiver)messages: 1

FS's receive(ANY) returns; the sender is recorded in m.source. FS finds that offset 0 of file 7 is in block 120.

Clientblocked (receive)File sys. (FS)blocked (receive)Disk driverrunninguser modemicrokernel: IPC (copies the message, wakes the receiver)messages: 2block 120 → DISK

FS cannot touch the disk directly either: it sends a second message to the driver and waits for the reply.

Clientblocked (receive)File sys. (FS)runningDisk driverblocked (receive)user modemicrokernel: IPC (copies the message, wakes the receiver)messages: 3data → FS

The driver reads the block through I/O the kernel permits and returns the data to FS in a third message. FS prepares the reply.

ClientreadyFile sys. (FS)runningDisk driverblocked (receive)user modemicrokernel: IPC (copies the message, wakes the receiver)messages: 4m → client

The fourth message carries the reply to the client; the client becomes ready.

ClientrunningFile sys. (FS)blocked (receive)Disk driverblocked (receive)user modemicrokernel: IPC (copies the message, wakes the receiver)messages: 4

FS goes back to the top of its loop and waits for new work.

ClientrunningFile sys. (FS)blocked (receive)Disk driverblocked (receive)user modemicrokernel: IPC (copies the message, wakes the receiver)messages: 4

The client's receive returns: the data is in m.result. One read took 4 messages, each with a user ↔ kernel switch; a monolithic kernel would finish the same job with function calls inside one system call.

Structures

MINIX 3: A Microkernel Example

User processesShellMakeCompiler…OtherServer processesFSPM (process)RSNetworkOtherDriver processesDiskTTYNetwork cardPrinterOtherKernel modeMicrokernel: interrupts, processes, scheduling, IPCkernel tasks: clock, system (sys)
Reincarnation server (RS)

Monitors the drivers' health and restarts a crashed driver (e.g. TTY) without the user noticing: a self-healing system.

Split privileges

Drivers are in user mode; they reach I/O ports only through kernel calls, to the extent allowed. A faulty driver cannot corrupt memory.

Structures

The Client–Server Model

user modekernel modeClientProcess serverTerminal serverFile serverMemory serverMicrokernelmessage

On a microkernel, processes fall into two classes: clients that request services and servers that provide them. They communicate only by messages.

Machine 1ClientKernelMachine 2File serverKernelMachine 3Process serverKernelMachine 4Terminal serverKernelNetworkmessage

A client need not know whether a message is handled locally or on another machine on the network: the model extends naturally to distributed systems (today's web and microservice architectures).

Message passing is not secure by itself: security depends on the kernel checking which process may send messages to which server.

Structures

The Tanenbaum–Torvalds Debate (1992)

Andrew Tanenbaum: microkernel
  • In his post “LINUX is obsolete” he called the monolithic design an outdated 1970s approach.
  • A microkernel is more modular, flexible and portable; damage from a bug in one component is contained.
  • As hardware gets faster, the overhead of message passing becomes negligible.
Linus Torvalds: monolithic
  • A monolithic kernel is simpler to design and implement; direct function calls are faster.
  • No message passing between processes is needed; in practice, code that works is what counts.
  • The open-source development model let Linux evolve quickly.
Both sides proved partly right: Linux stayed monolithic but gained flexibility through loadable modules, user-space drivers (FUSE, VFIO) and eBPF; microkernels spread in safety-critical and embedded systems (QNX, seL4).

Structures

Modular Structure: Loadable Kernel Modules

  • The kernel holds only core components; other services are loaded at boot or at run time as modules (Linux LKM, FreeBSD, Solaris).
  • Like layering (defined interfaces) but more flexible: any module can call any other. Like a microkernel, but no messages are needed: modules run in kernel mode.
file systemsdevice driversnetwork protocolsexecutable formatsCore kernelscheduling, memory, IPC

At boot the kernel and the required modules from initramfs are loaded. lsmod lists the loaded modules.

file systemsdevice driversnetwork protocolsexecutable formatsCore kernelscheduling, memory, IPCusb_storage

A USB stick is plugged in: a udev event loads the driver (with its dependencies) via modprobe usb-storage; the vfat module is loaded when the stick is mounted.

file systemsdevice driversnetwork protocolsexecutable formatsCore kernelscheduling, memory, IPCusb_storage + vfat

The module registers itself with the kernel and works through direct function calls: fast, but no isolation; a faulty module can crash the kernel.

file systemsdevice driversnetwork protocolsexecutable formatsCore kernelscheduling, memory, IPCusb_storage + vfat

When its use count is 0, modprobe -r (or rmmod) unloads the module. Modules must match the kernel version.

Structures

Hybrid Kernels: Windows and macOS

user modekernel modeApplicationsEnvironment subsystems (Win32…)System servicesntdll.dll: system-call stubs (Nt… functions)ExecutiveI/O, memory, process and object managers,security reference monitor, cachewin32k.sys (graphics)Device driversKernel: scheduling, interrupts, synchronizationHAL (hardware abstraction layer)Hardware

Windows NT: microkernel ideas (subsystems, object/message-based design) are kept, but for performance the executive, graphics and drivers were moved into kernel mode.

user modekernel modeApplicationsFrameworks: Cocoa / SwiftUI, Metal, Core …libSystem (libc, system-call stubs)XNU kernel (Darwin)MachIPC, scheduling,virtual memoryBSDPOSIX, networking, filesystems, securityI/O Kitobject-orienteddriver frameworkNew drivers are moving out of the kernel into DriverKit in user spaceHardware (Apple silicon / x86-64)

macOS / iOS XNU: the Mach microkernel and the BSD layer share one kernel address space: microkernel modularity + monolithic speed.

Structures

Exokernels

Web serverLibOS:custom net / cacheDatabaseLibOS:custom memory / diskPOSIX applicationLibOS:ExOS (UNIX-like)Exokernel: only secure multiplexing and protectionwhich disk block / memory page / CPU slice belongs to whom?disk blocksmemory pagesCPU time slicenetwork card
  • A research architecture by Engler and Kaashoek at MIT (1995): the kernel Aegis and the library OS ExOS. Not a commercial OS.
  • A VM gets a copy of the machine; an exokernel hands out a share of a resource and checks ownership, with no remapping layer needed.
  • Separates management from protection: the kernel only tracks who owns which resources; abstractions (files, virtual memory) come from application-level LibOSes.
  • High performance through application-specific memory management and caching, but applications are complex to build. The idea lives on in unikernels and kernel-bypass I/O such as DPDK / SPDK.

Structures

Comparing the Structures

StructureWhat is in the kernel?StrengthWeaknessExample
Simpleeverything, unrestrictedsmall, simpleno protectionMS-DOS
Monolithicall servicesspeedno fault isolationUNIX, Linux
Layeredhierarchical layerseasy to verifyoverhead, hard to defineTHE, MULTICS
MicrokernelIPC, scheduling, memoryreliabilitymessage overheadMINIX 3, QNX, seL4
Modularkernel + modulesflexibility, speedmodule = full privilegeLinux, FreeBSD
Hybridmicro + selected servicesbalancecomplexityWindows, macOS
Exokernelprotection onlyapp-specific speedhard to developAegis/ExOS

Real systems are not pure: Linux is monolithic + modular, Windows and macOS are hybrid, and nearly all are layered to some degree.

Virtual Machines

The Virtual-Machine Concept

  • A hypervisor (VMM) creates virtual machines on one physical machine, each looking like an independent computer.
  • Each guest OS believes it has its own CPU, RAM, disk and I/O devices; different OSes can run concurrently on the same hardware.
  • The idea goes back to IBM VM/370 (1972); today it underpins cloud computing: server consolidation, isolation, snapshots, live migration.
  • A hypervisor runs on the hardware (type 1) or on a host OS (type 2). A container carries no kernel of its own; it isolates processes that share one kernel.
processprocessprocessKernelaccesses hardware directlyHardwareprocesseskernelVM1processeskernelVM2processeskernelVM3Virtual machine manager (hypervisor)Hardware(a) Nonvirtual machine(b) Virtual machines

Hardware and Structure

Symmetric Multiprocessing and Multicore Architecture

CPU0registerscacheCPU1registerscacheCPU2registerscachebusMain memory (shared)

SMP: each CPU has its own registers and cache and shares memory; every CPU can do any work, the OS included. Kernel data structures must be protected by locks (Linux's “big kernel lock” was removed entirely in 2011).

one chipCore 0registersL1 cacheCore 1registersL1 cacheL2 / L3 cache (shared)Main memory

Multicore chip: cores on the same chip share nearby caches and communicate faster with less energy. P/E (performance/efficiency) cores, common in 2026, give the scheduler new work.

Linking and Booting

Compiling, Linking and Loading

main.cCompilergcc -cmain.oobject fileother .o,libm.aLinkerldprogramexecutableLoaderexecve + ld.solibc.so.6sharedprocess in memory(running)

The compiler turns source code into a relocatable object file: addresses are not final yet and external symbols (e.g. printf) are unresolved.

main.cCompilergcc -cmain.oobject fileother .o,libm.aLinkerldprogramexecutableLoaderexecve + ld.solibc.so.6sharedprocess in memory(running)

The linker combines object files and static libraries, resolves symbols, fixes up addresses and produces an executable.

main.cCompilergcc -cmain.oobject fileother .o,libm.aLinkerldprogramexecutableLoaderexecve + ld.solibc.so.6sharedprocess in memory(running)

The shell calls execve; the kernel's loader reads the file header, maps the segments into the address space and starts the dynamic linker (ld-linux.so).

main.cCompilergcc -cmain.oobject fileother .o,libm.aLinkerldprogramexecutableLoaderexecve + ld.solibc.so.6sharedprocess in memory(running)

Shared libraries (libc.so.6) are linked at run time and shared among processes. Formats are OS-specific: ELF (Linux), PE (Windows), Mach-O (macOS); so programs cannot move directly between OSes.

Linking and Booting

Booting the Operating System

Booting is everything from loading the kernel into memory to starting the first user process. The old BIOS (1981, 16-bit real mode) ran the MBR code in the disk's first sector; UEFI loads a file (.efi), not a sector. On Linux systemd-analyze shows the time of each stage.

Power on /resetUEFIfirmwareBoot loaderGRUB 2 /systemd-bootKernel+ initramfsRoot FSmountedPID 1systemdThe CPU starts running firmware at a fixed address.

At power-on the CPU resets and starts executing firmware in flash from a fixed address set by the hardware.

Power on /resetUEFIfirmwareBoot loaderGRUB 2 /systemd-bootKernel+ initramfsRoot FSmountedPID 1systemdPOST tests and initializes the hardware; the boot loader on the EFI system partition is found.Secure Boot verifies the signature of every stage.

UEFI tests memory and devices with the power-on self-test (POST), then, following the order in NVRAM (NVMe, USB, network/PXE), loads the boot loader from the EFI system partition (FAT32) on a GPT disk. With Secure Boot on, its signature is verified.

Power on /resetUEFIfirmwareBoot loaderGRUB 2 /systemd-bootKernel+ initramfsRoot FSmountedPID 1systemdThe boot loader offers a choice of kernels and loads the kernel and initramfs into memory.Older systems: BIOS + MBR.

The boot loader shows a menu, puts the chosen kernel and the initial RAM disk (initramfs) in memory and jumps to the kernel.

Power on /resetUEFIfirmwareBoot loaderGRUB 2 /systemd-bootKernel+ initramfsRoot FSmountedPID 1systemdThe kernel decompresses itself, detects hardware, loads drivers;initramfs provides a temporary root file system.

The kernel starts memory management, the scheduler and drivers; scripts in initramfs load the modules needed.

Power on /resetUEFIfirmwareBoot loaderGRUB 2 /systemd-bootKernel+ initramfsRoot FSmountedPID 1systemdThe real root file system is mounted (e.g. after unlocking an encrypted disk).

The real root file system is mounted and initramfs is discarded.

Power on /resetUEFIfirmwareBoot loaderGRUB 2 /systemd-bootKernel+ initramfsRoot FSmountedPID 1systemdThe first user process starts; it launches services in parallel and opens the login screen.

The kernel starts PID 1 (systemd), which brings up services, the network and the login screen. From then on every process descends from PID 1. On Windows: winload.efi → ntoskrnl.exe → smss.exe → winlogon.exe.

Summary

Review Questions

  1. Why can't a user-mode program execute I/O instructions directly? What happens if it tries?
  2. What is the difference between printf and write? Which one is a system call?
  3. Why is fork() “called once, returns twice”? What does it return in the parent and in the child?
  4. What happens if a driver crashes on a microkernel? On a monolithic kernel?
  5. Do loadable modules make Linux a microkernel? Why?
  6. What is the first user process the kernel starts at boot? Why does it matter?
Show answers
  1. I/O is privileged; with the mode bit at 1 the hardware traps and the OS kills the process (protection).
  2. printf is a library function that formats in user mode; when needed it makes the write system call.
  3. After the call there are two processes, both continuing from the same point: the parent gets the child's PID, the child gets 0 (error: −1).
  4. On a microkernel only that server process crashes, and it can be restarted; on a monolithic kernel the whole kernel can go down.
  5. No: modules run in kernel mode in the same address space and communicate by function calls, not messages.
  6. PID 1 (systemd or init): it starts the services and the login screen; every other process descends from it, and it adopts processes whose parent has died.

Summary

References

  • Silberschatz, Galvin and Gagne, Operating System Concepts, 10th ed., Wiley, 2018 (Chapters 2 and 18).
  • Tanenbaum and Bos, Modern Operating Systems, 4th ed., Pearson, 2014 (Sections 1.5–1.7 and Chapter 7).
  • Arpaci-Dusseau and Arpaci-Dusseau, Operating Systems: Three Easy Pieces (OSTEP), version 1.10, pages.cs.wisc.edu/~remzi/OSTEP.
  • Linux man pages: syscalls(2), syscall(2), fork(2), pipe(7), mount(8).
  • Engler, Kaashoek and O’Toole, “Exokernel: An Operating System Architecture for Application-Level Resource Management”, SOSP 1995.

The End

Chapter 2: Operating-System Structures
Previous: Chapter 1: Introduction · Next: Chapter 3: Processes
1 / 1