Skip to content

Chapter 3 of 8

Processes, systemd, and Scheduled Jobs

Every running program on Linux is a process identified by a PID, and operators routinely need to inspect, signal, and reorder them. The ps command produces a static snapshot: ps aux shows every process with detailed fields, ps -ef uses full-format output, and ps -u username filters by user. The interactive top (and its colorful cousin htop) refreshes continuously and offers single-keystroke actions — k to kill a process, M to sort by memory, P by CPU, and q to quit. To influence a running process, kill sends signals by PID: the default and most graceful is SIGTERM (15); SIGKILL (9) forces immediate termination but cannot be caught or cleaned up; SIGHUP (1) prompts many daemons to reload configuration; SIGSTOP (19) pauses and SIGCONT (18) resumes; kill -l lists every signal number and name. Process priority is adjusted through nice, whose scale runs from -20 (highest priority) to 19 (lowest) — a regular user can only increase niceness — and renice changes it for an existing PID, while nohup shields a command from SIGHUP so that it survives the closing of its controlling terminal, redirecting its output to nohup.out by default.

Job control adds a session-local layer on top of system processes. Appending & launches a command in the background, and Ctrl+Z suspends the current foreground job. The jobs command enumerates shells jobs with their numbers and states (running, stopped, or done), bg %1 resumes job 1 in the background, fg %1 pulls it back into the foreground, and disown %1 detaches it from the shell so it survives logout. PID 1 holds a special place: it is the init process started by the kernel and becomes the ancestor of every other userspace process, automatically adopting any orphaned children (and reaping their zombies). On modern distributions PID 1 is systemd, which is unkillable even by kill -9 — to replace it you must re-execute the binary or reboot. Zombies themselves, marked Z in ps state, only consume a slot in the process table; cleanup requires the parent to call wait() or to be sent SIGCHLD, or, if the parent is gone, for PID 1 to reap them automatically.

systemd has effectively replaced the older SysV init and supersedes ad-hoc scripts. Its primary management tool is systemctl: start, stop, restart, enable (start at boot), and status act on units, while list-units --type=service enumerates them. A unit file lives in /etc/systemd/system/ (or /lib/systemd/system/) and is divided into three sections: [Unit] carries a human-readable Description and ordering hints like After=network.target; [Service] specifies how the daemon runs, including ExecStart, an optional restart policy (Restart=always), and the user to drop privileges to (User=www-data); [Install] integrates with the boot sequence via WantedBy=multi-user.target. After any edit, systemctl daemon-reload picks up the changes. Targets are systemd's replacement for SysV runlevels — poweroff.target, rescue.target (single user), multi-user.target (no GUI), graphical.target, and reboot.target — and systemctl get-default plus set-default change the boot state.

Logs and scheduling round out the systemd toolkit. journalctl queries the systemd journal: -u nginx filters by unit, -f follows new entries (like tail -f), --since "1 hour ago" filters by time, -p err restricts the priority, and -b shows only messages from the current boot. The journal lives in volatile memory by default; making it persistent requires creating /var/log/journal and restarting systemd-journald, after which retention can be controlled with SystemMaxUse= and MaxRetentionSec= in /etc/systemd/journald.conf. For recurring tasks, systemd timer units (*.timer) can replace cron. A timer pairs with a service whose ExecStart runs the actual work; the timer's [Timer] section uses OnCalendar=*-*-* 02:00:00 for absolute times and Persistent=true to catch up after downtime, with commands like systemctl list-timers and enable managing activation. When cron is still preferred, crontab -e edits a per-user schedule whose columns encode minute, hour, day of month, month, and day of week — for example, 0 2 * * * /backup.sh runs nightly at 02:00, while */15 * * * * /check.sh fires every fifteen minutes, and the @reboot shortcut executes once at startup. For one-shot future work, at queues a job specified inline (e.g., at 14:30 followed by commands and Ctrl+D), with atq listing pending jobs, atrm removing them, and the atd service managing execution.

All chapters
  1. 1Core Command-Line Tools and Text Processing
  2. 2The Filesystem Layout, Permissions, and Ownership
  3. 3Processes, systemd, and Scheduled Jobs
  4. 4User Administration, Security, and the Boot Process
  5. 5Networking, SSH, and Firewalls
  6. 6Storage, Filesystems, and Memory
  7. 7Shell Scripting and Package Management
  8. 8System Observability, Performance Tuning, and Containers

Drill it

Reading is not remembering. These come from the Linux Administration deck:

Q

What does the ls command do in Linux?

The ls command lists directory contents. Common flags:-l long format with permissions, owner, size, date-a show hidden files (dotfiles)-h human-readable sizes-R...

Q

How does grep search for patterns in files?

grep searches text using patterns.Usage: grep [options] pattern [file...]Key flags:-i case-insensitive-r recursive search-n show line numbers-v invert match-E e...

Q

How do you use the find command to locate files?

find searches the directory tree.Examples:find /home -name "*.txt" — find by namefind . -type f -mtime -7 — files modified in last 7 daysfind / -size +100M — fi...

Q

What is awk and how is it used for text processing?

awk is a powerful text-processing language that operates on fields and records.Examples:awk '{print $1, $3}' file — print columns 1 and 3awk -F: '{print $1}' /e...