Part 5 of 6 · 3 min read
A short routine
A short routine
Think of a pilot's checklist: a fixed order, the same each time, so that nothing is forgotten when the day is bad. The analogy stops in one place: a checklist is written once for an aircraft, and a Linux machine's list changes with the problem.
In plain words: Five habits make the toolbox fast to use. First, ask the questions in the fixed order of section 1: machine, memory, disk, process, wait. Second, read the manual: man 5 proc describes every field of /proc, and man 1 ps explains each column. Third, check the exit status, $?, of every command in a script: 0 is success (Level 1). Fourth, record the numbers before a change and again after, so that the effect is clear. Fifth, prefer read-only commands first: all the commands in this page only read.
A worked example. A short snapshot script for a bug report: date; uptime; free -m; df -h; vmstat 1 3; ps -eo pid,stat,rss,comm --sort=-rss | head. It takes 3 seconds and fits in a ticket. A reader on another machine can compare the numbers with their own and see the difference without being on the same host.
The key lines. The goal is not to know all commands, but to know which question each answers and to get the answer in under a minute.
Snapshot
A snapshot of a system, in operations work, is a set of command outputs taken at one moment, with the date, so that the state of the machine at that time can be studied or compared later.
Example: the output of uptime, free, df and vmstat in one file with a date line.
Interview angle
A common question is "A server is slow. What do you check first?" A good answer begins with the questions, not the tools: is the machine busy (load against cores), is memory short, is the disk busy or full, then which process and what it waits for. It names uptime, free, vmstat, df, ps and strace.
Check yourself:
1. What does exit status 0 mean?
2. Where is every field of /proc described?
3. Why take a snapshot before a change?
Words you will meet
| Word | Meaning |
|---|---|
| Observability | Seeing what a system does from outside, without changing it. |
| VSZ / RSS | Virtual size / resident (real) size of a process. |
| NLWP | Number of light-weight processes, that is, threads. |
| Load average | Smoothed count of tasks running or ready, over 1, 5 and 15 minutes. |
wchan |
The kernel function a sleeping process waits in. |
| Snapshot | Command outputs taken together at one moment. |
Quick notes
- Start from a question. Most tools read
/procand/sys. ps -o pid,nlwp,vsz,rss,stat,commgives threads, virtual and resident size, and state.- The worker mapped 100 MiB and touched 30:
VSZ121,504 kB,RSS32,588 kB. free(memory),vmstat(CPU, swap, I/O),df(space) anduptime(load) describe the machine.- Read the load against the number of cores. Compare with a normal day.
- Take a snapshot before and after a change.