Part 1 of 8 · 1 min read
Why this page comes second
In this module you will
- Explain why the processor has two modes and what a privileged instruction is.
- Walk through a system call from the C function to the kernel and back.
- Read an
errnovalue and handle a failed system call in C. - Trace the system calls a simple program makes, using
strace. - Explain how a timer and traps let the OS stay in control.
Page 1 said that programs reach the OS through system calls. This page shows what really happens during one, and why the OS needs help from the hardware to stay safe. Later pages on processes, memory and files all start with a system call. The main sources are "Operating System Concepts" (OSC), chapters 1 and 2, and "The Linux Programming Interface" (TLPI), chapter 3. Code was compiled and run on Linux before it was written here. Numbers marked "made up" only show the idea.
About this example About this example
Real: The C programs and the strace and shell outputs in this page were run on a 64-bit Linux test machine, and system call number 39 for getpid is from that machine.
Scripted: Output lines are shown as printed on that machine. Process IDs differ on each run.
Not real: The table of eight steps in a system call is a simplification of what the processor and the kernel really do.