Processes, jobs, and system services
This domain, Processes, jobs, and system services, covers how programs become processes, how to inspect and signal them, how shell job control differs from persistent services, and how systemd supervises daemons.
Processes and signals
- A process has a PID and a PPID;
forkclones it andexecreplaces the image. Common states are R (running), S (sleeping), D (uninterruptible), Z (zombie), and T (stopped). - Inspect with
ps aux,ps -ef --forest,top,pgrep -a, andpidof. - Signals:
SIGTERM(15, polite default),SIGKILL(9, cannot be caught),SIGHUP(1, often reload),SIGSTOPandSIGCONT. - Priority:
nice -n 10 cmdstarts with lower priority;renice -n 5 -p PIDadjusts a running process. Lower nice values mean higher priority.
Jobs and services
- Shell jobs:
cmd &,jobs,fg %1,bg %1, Ctrl-Z,disown. Jobs die with the shell unless you usenohup cmd &or a terminal multiplexer. - systemd units include
.service,.timer,.socket, and.mount. Usesystemctl start,stop,restart,reload,status,enable,disable,mask. enablecreates boot-time symlinks;startacts only now. Logs come fromjournalctl -u sshd -b --since '1 hour ago'.
Worked example
A daemon ignores systemctl stop. Reasoning: systemd sent SIGTERM and the process did not exit within TimeoutStopSec. Check systemctl status and journalctl -u name; if the process is stuck in D state, investigate I/O before forcing anything. You can send another signal with systemctl kill -s SIGKILL name, or adjust KillSignal and TimeoutStopSec in a drop-in created by systemctl edit name. Keep SIGKILL as a last resort because it prevents cleanup.
Traps
- Reaching for
kill -9first. - Believing
systemctl startsurvives a reboot. - Editing a unit file without
systemctl daemon-reload. - Confusing a zombie, which is already dead and waiting for its parent, with a running process.