Based on the Linux Master 1 exam syllabusReport an error
ps aux (usage, STAT) / ps -ef (tracing PPID) / top (real time) / pstree (hierarchy) / pgrep (name to PID).nice is used when launching, renice on a running process.sar, then narrow down with vmstat (whole system), iostat (disks), mpstat (cores), and pidstat (processes) to tell CPU, I/O, and memory bottlenecks apart.ls, the shell creates a new process and runs ls inside it.init on traditional init systems, systemd on modern ones. It is the first user-space process the kernel starts right after boot, and the ancestor of every process.echo $$ # PID of the current shell itself
echo $PPID # parent PID of the current shell
ps -p 1 # check what PID 1 is (systemd or init)PID 1 (init/systemd) never dies. A child whose parent exited first (an orphan process) is automatically adopted by PID 1 and cleaned up. This adoption mechanism is the key thing that keeps the system from filling up with zombies.
Try it yourself: Run bash once more to enter a subshell, check its PID with echo $$, and compare whether echo $PPID matches the PID of the outer shell. When you exit, you return to the original PID. You can see the process hierarchy with your own eyes.
ps (process status) shows a snapshot of the current processes.| Command | Style | Meaning | Notes |
|---|---|---|---|
ps aux | BSD (no hyphen) | All processes of all users | Shows %CPU, %MEM, START, etc. |
ps -ef | UNIX (with hyphen) | Full list of all processes | Shows the PPID column |
ps -u user | UNIX | Processes of a specific user | Filter by user |
ps -p PID | UNIX | Info on a specific PID | Single process |
ps aux # all processes + CPU/memory usage
ps -ef # all processes + PPID (good for tracing parents)
ps -ef | grep nginx # pick out only a specific program's processes
ps aux --sort=-%cpu # sort by CPU usage, descendingps aux, you need to know what each letter means.| STAT | Meaning |
|---|---|
| R | Running or runnable (waiting for CPU) |
| S | Interruptible sleep (Sleeping) |
| D | Uninterruptible sleep (mostly I/O) |
| T | Stopped (Ctrl+Z, etc.) |
| Z | Zombie (terminated but not reaped) |
| < | High priority (low nice) |
| N | Low priority (high nice) |
⚠️ Trap:
ps auxtakes no hyphen, whileps -efdoes. Mixing them as inps -auxmay produce a warning or be interpreted differently on some systems. Remember it as "aux is bare, ef has a hyphen". Also,Z(zombie) is a state where the parent has not reaped (wait) the terminated child, so only the PID remains — the key topic of Day 2.
The BSD syntax of ps aux comes from Berkeley Unix, and the UNIX syntax of ps -ef from AT&T System V. Linux's procps accepts both, so you can see the same information either way. Exams often test the difference in purpose: "aux is for usage, ef is for tracing parents".
ps is a still photo, top is a video. It refreshes every 3 seconds by default and lists the processes using the most CPU and memory at the top.top # enter the real-time process monitortop screen show up in practical exams.| Key | Action |
|---|---|
P | Sort by CPU usage (default) |
M | Sort by memory usage |
k | Send a signal to a process (kill) — enter a PID |
r | Change priority (renice) — enter a PID |
1 | Expand per-core CPU usage |
q | Quit |
yum install htop or apt install htop).The exam point is that top ships with every distribution, while htop is an external tool that must be installed separately. Both send signals with "k" and change priority with "r" (top) / F9 (htop).
Try it yourself: Run top, press uppercase M to switch to memory sorting, and press 1 to see whether per-core usage expands. Exit with q. Note that the shortcuts are case-sensitive (P is sorting, while lowercase p does something else).
ps -ef | grep combination is common, but it has the drawback that the grep process doing the search shows up in the results too.pgrep cleanly extracts just the PIDs by name.pgrep sshd # print only the PIDs of sshd processes
pgrep -l sshd # PID + process name together
pgrep -u root cron # PIDs of cron processes owned by root
pgrep -c bash # number of matching processespstree draws processes as a parent-child tree. You can see at a glance who launched whom.pstree # full process tree
pstree -p # show each process's PID too
pstree -p 1 # only the tree under systemd (PID 1)Try it yourself: Run pstree -p | head -20 to see the top of the system tree. systemd(1) or init(1) is at the very top, and every service branches out below it. You can see with your own eyes that PID 1 is the ancestor of everything.
kill is not a command that "kills" — it is a command that "sends the signal with the specified number". Depending on the signal type, the behavior differs: terminate, reconfigure, pause, and so on.| Number | Name | Meaning | Can be ignored? |
|---|---|---|---|
| 1 | SIGHUP | Terminal disconnected / re-read config (reload) | Yes |
| 9 | SIGKILL | Forced termination (immediate, unconditional) | No |
| 15 | SIGTERM | Graceful termination request (default) | Yes |
| 2 | SIGINT | Interrupt (Ctrl+C) | Yes |
| 18/19 | SIGCONT/SIGSTOP | Resume / stop | STOP cannot |
kill 1234 # send the default signal 15 (SIGTERM) to PID 1234
kill -9 1234 # force-terminate with signal 9 (SIGKILL)
kill -15 1234 # explicitly request graceful termination with 15 (SIGTERM)
kill -1 1234 # signal 1 (SIGHUP) — usually makes a daemon re-read its config
kill -HUP 1234 # can also be specified by name
kill -l # full list of signal numbers <-> nameskill only a PID with no option. It is a polite request that says "I'll give you time to clean up, so exit gracefully", which lets the process close open files and delete temporary files before exiting.⚠️ Trap: You must not always reach for 9 first. The correct order is to try 15 (graceful termination) first, and use 9 (forced) only if the process still won't die. Also remember that SIGKILL (9) and SIGSTOP (19) are the only two signals that cannot be ignored or blocked.
killall (by name) or pkill (by pattern).killall httpd # send signal 15 to every process named httpd
killall -9 httpd # force termination
pkill -u alice # all processes of user alice
pkill -HUP sshd # send HUP to sshd (re-read config)kill sends signals by PID, while killall/pkill do so by name/pattern. SIGHUP (1) is often used to tell a daemon "don't die, just re-read your config file" (e.g. kill -HUP $(pgrep -x sshd)). That's why signal 1 is synonymous with "reload without restart".
The H-U-P in SIGHUP stands for "Hang Up" (hanging up the phone). In the old days, when a modem terminal connection dropped, the kernel sent SIGHUP to the processes attached to that terminal. As daemons today reinterpret this signal as "re-read config", it has become the standard signal for zero-downtime service reloads. The nohup (no hang up) command is the tool that makes a process ignore this SIGHUP so it stays alive after you log out.
| Nice value | Meaning | Priority |
|---|---|---|
| -20 | Most selfish (never yields) | Highest |
| 0 | Default | Normal |
| 19 | Nicest (yields the most) | Lowest |
nice -n 10 ./backup.sh # run with nice lowered to 10 (yielding)
nice -n -5 ./urgent.sh # run with nice raised to -5 (priority)
nice ./job.sh # if -n is omitted, the default +10 is appliedrenice.renice 15 -p 1234 # change PID 1234's nice to 15
renice -n 5 -p 1234 # can also be specified with the -n option
renice 10 -u alice # set the nice of all of alice's processes to 10Only root can set a negative nice (raising priority). A regular user can only raise the nice number of their own processes (make the number bigger), and cannot take back a priority they have already yielded. Also, nice is for "launching a new process" while renice is for "a process that is already running". The default applied by nice (when -n is omitted) is +10.
The nice value and the actual scheduling priority (PRI) seem to go in opposite directions but are linked. The lower the nice (the closer to -20), the higher the priority and the more often the process gets the CPU. In top, the NI column is the nice value and the PR column is the kernel priority.
Try it yourself: Launch the most yielding process with nice -n 19 sleep 100 &, then check that the NI column is 19 with ps -o pid,ni,cmd -p $!. Then change it with renice 5 -p $! and check again; NI drops to 5 (a regular user can only raise it).
top tells you "who is eating the CPU right now", but it cannot answer "what happened at 3 a.m. last night?"sar (System Activity Reporter) reads that history back for you.sa1, registered in /etc/cron.d/sysstat, takes a snapshot every 10 minutes by default.sa2 produces a daily summary report, and the raw data accumulates in per-date files sa01, sa02, and so on.| Item | RHEL family | Debian family |
|---|---|---|
| Install | dnf install sysstat | apt install sysstat |
| Start collection | Start the service after installing | Must change to ENABLED="true" in /etc/default/sysstat to start |
| Data location | /var/log/sa/saDD | /var/log/sysstat/saDD |
sar lets you pick the resource to view with a single option letter.| Option | What it shows | Values to watch |
|---|---|---|
-u | CPU usage (default) | %user %system %iowait %idle |
-r | Memory usage | kbmemfree %memused kbcached |
-W / -S | Swap activity / swap space | pswpin/s pswpout/s, %swpused |
-b | Overall disk I/O transfer rate | tps rtps wtps |
-d | Disk activity per device | await %util |
-n DEV | Traffic per network interface | rxkB/s txkB/s |
-q | Run queue and load average | runq-sz ldavg-1/5/15 |
sar -u 1 5 # watch CPU live, 5 samples at 1-second intervals
sar -r # full memory history collected today
sar -n DEV 2 3 # per network interface, 3 samples at 2-second intervals
sar -f /var/log/sa/sa15 # look up past history from the file for the 15th
sar -u -s 03:00:00 -e 04:00:00 # view only a specific time windowThe value of sar is looking back at the past with -f. If you log in after an incident has passed and run top, everything is already back to normal, but if sar data has accumulated you can lay CPU, memory, disk, and network side by side for that moment and see what spiked first.
On Debian and Ubuntu, merely installing sysstat does not start collection. You must change ENABLED in /etc/default/sysstat to "true" and restart the service before data starts to accumulate.
| Tool | Question it answers | Key columns |
|---|---|---|
vmstat 1 | What is the whole system blocked on right now? | r (waiting to run), b (waiting on I/O), si/so (swap in/out), wa |
iostat -x 1 | Which disk is how busy? | tps, await (average response, ms), %util (device saturation) |
mpstat -P ALL 1 | Which CPU core is the load concentrated on? | Per-core %usr %sys %iowait |
pidstat 1 | Which process is consuming resources? | -u CPU, -r memory, -d disk I/O |
free -h | Is memory really running short? | available (actual free), buff/cache |
uptime | Recent load trend | load average over 1, 5, 15 minutes |
sar, iostat, mpstat, and pidstat are in the sysstat package, while vmstat, free, and uptime are basic tools of procps (procps-ng).The three numbers at the top of top and uptime are the average load over 1, 5, and 15 minutes.
Definition on Linux: the average number of "processes that are running or waiting to run (R) + processes in uninterruptible sleep (D, usually disk I/O)".
The yardstick is the number of CPU cores. With 4 cores, 4.0 means "completely full with no slack", and 8.0 is an overload where half are waiting for their turn. Check the core count with nproc.
Look at the slope of the three numbers. 10.0 4.0 2.0 means the load is rising sharply, while 2.0 4.0 10.0 means the event has already passed.
On Linux, the load average includes disk I/O wait (D state), so the value can shoot up when storage is slow even if the CPU is idle.
| Bottleneck | Decisive metric | Supporting signs | Remedy direction |
|---|---|---|---|
| CPU bound | High %user+%system, low %iowait | r in vmstat larger than core count, a specific core saturated in mpstat | Add cores, improve algorithms, yield to batch jobs with nice |
| I/O bound | High %iowait | Large b in vmstat, %util near 100% and a surge in await in iostat, D state in ps | Replace disks (SSD), distribute I/O, improve queries/caching |
| Memory shortage | Sustained si/so (swap in/out) | available in free bottomed out, rising pswpout/s in sar -W, OOM logs | Add memory, reduce process usage |
nproc # core count — the baseline for interpreting load average
vmstat 1 5 # compare r / b / si / so / wa on one screen
iostat -x 1 3 # check disk saturation with await and %util
pidstat -d 1 3 # pinpoint the process actually generating I/OA small free value in free does not mean memory is short. Linux uses spare memory as much as possible for buffers and cache and gives it back immediately when needed. Judge real free memory by the available column; the real evidence of a shortage is swap in/out (si/so) continuously occurring. If swap usage is high but there is no inflow or outflow, those are just pages that have gone to sleep, not a bottleneck.
Try it yourself: Leave vmstat 1 10 running, and in another terminal create disk load with dd if=/dev/zero of=/tmp/t bs=1M count=1000 oflag=direct, then see whether b and wa rise together. If %util for that device sticks at 100% in iostat -x 1, that is the indicator combination for "I/O bound". When done, rm /tmp/t.
ps aux. R (running) S (sleeping) D (I/O wait) T (stopped) Z (zombie).kill and can be ignored.-f lets you open a past date's file.Click a choice to reveal the answer and explanation.
Question 1
Which command is most appropriate for printing all processes together with their parent process (PPID) information?
Question 2
When you give the kill command only a PID with no option, which signal is sent by default?
Question 3
Which of the following signals cannot be caught or ignored by a process and therefore always takes effect?
Question 4
Which of the following is a correct statement about the nice value?
Question 5
You want to terminate every process named httpd at once. Which command is most appropriate?
Question 6
You want to change the nice value of the running process with PID 2000 to 10. Which command is correct?
Question 7
What is the most common purpose of sending SIGHUP (signal 1) to a running daemon?