Part 7 of 8 · 3 min read
Looking ahead
Looking back at Level 0, looking ahead to Level 1
Think of the last lesson of a course, when the teacher lays all the parts of a machine on one table and names each. The analogy stops in one place: a table shows parts at rest, and the pages of this level describe parts at work.
In plain words: The six pages of this level fit together like this. The OS manages resources and offers services (page 1). It protects itself with user and kernel modes and offers services through system calls (page 2). Its kernel can be built in several ways (page 3). It starts up in stages ending in a first process (page 4). It reacts to devices, faults and requests through interrupts and traps (page 5). And you can watch all of it from outside with a handful of commands (this page).
A closing exercise in reading: take the line write(1, "hi\n", 3) = 3 from an strace. It shows the system call (page 2), on descriptor 1, the standard output (section 3 above), executed by the kernel in kernel mode after a trap (page 5), made by a process whose PID you could find in ps (section 2), with the result 3, meaning three bytes were written.
Level 1 now opens the box called process: how one is created with fork, how it ends, how it appears in memory, and how the OS switches between processes using the interrupts of page 5.
Interview angle
Answer in your head first, then open it.
How do you see what a process is doing on Linux?
ps for the list, /proc/PID for details, strace for system calls, ls /proc/PID/fd for open files.
What are descriptors 0, 1 and 2?
Standard input, output and error.
What do user and sys time mean?
Processor time spent in the program's own code, and in the kernel on its behalf.
What is /proc?
A virtual file system through which the kernel exposes its data as files.
Check yourself:
1. Name the page where each of the six pages' main ideas was introduced, in order.
2. In the write line above, what does the final 3 mean?
3. What will Level 1 explain first?
Words you will meet
| Word | Meaning |
|---|---|
| PID | The process ID number |
| Parent process | The process that started another |
| Resident set size | The part of a process's memory currently in physical memory |
| Standard input, output, error | Descriptors 0, 1 and 2 |
| User time, system time | Processor time in user mode and in the kernel |
| Manual page | The built-in documentation for a command or call |
Quick notes
- /proc is a virtual file system that the kernel builds in memory when files are read.
- /proc/PID/status shows a process's fields, including VmRSS.
- Standard streams are descriptors 0, 1 and 2, and /proc/PID/fd shows what they point to.
- A system call costs tens to hundreds of nanoseconds. Time it by repeating it many times.
- strace shows the system calls of a program, and strace -c counts them.
- The manual sections: 1 for commands, 2 for system calls, 3 for library functions.