teluzia.Cloud Engineer · Day 9
CHAPTER 02 · LINUX ADMINISTRATION AND SHELL SCRIPTING

Processes, signals and systemd

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Manage a harmless background process and inspect the service manager separately. Processes have runtime identities and signals; systemd supervises units when it is the machine’s init system. WSL installations may differ, so verify PID 1 before assuming systemctl is available. A process is a running program with a process ID, state, parent and resources. The shell can start a command in the background with &, and $! captures that new background job’s PID. ps inspects selected processes; jobs describes jobs managed by your current shell. Signals notify processes of events. SIGTERM requests termination and allows cooperative cleanup; SIGKILL forcibly stops a process and cannot be caught. Some programs use other signals for reload or interruption, but meanings depend on the program. Always verify a process before sending it a signal.

Think of it this way

A process is a running worker; a signal is an instruction to the worker; systemd is the supervisor that hires and restarts workers.

TOPIC 01 / 03Step by step

Processes and PIDs

A process is a running program with a process ID, state, parent and resources. The shell can start a command in the background with &, and $! captures that new background job’s PID. ps inspects selected processes; jobs describes jobs managed by your current shell. Start sleep 120 & and immediately assign lab_pid=$!; ps -p "$lab_pid" -o pid,ppid,stat,args shows only that practice worker. Capturing the exact PID avoids broad process matching and lets you correlate a running command with its parent, state and eventual termination evidence safely. Using a broad killall pattern can terminate unrelated work; target the PID captured from your own harmless process rather than guessed process-name matches today.

WORKED EXAMPLE
Start sleep 120 & and immediately assign lab_pid=$!; ps -p "$lab_pid" -o pid,ppid,stat,args shows only that practice worker.
Why this matters

Capturing the exact PID avoids broad process matching and lets you correlate a running command with its parent, state and eventual termination evidence safely.

A common trap

Using a broad killall pattern can terminate unrelated work; target the PID captured from your own harmless process rather than guessed process-name matches today.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Processes and PIDs

A process is a running program with a process ID, state, parent and resources. The shell can start a command in the background with &, and $! captures that new background job’s PID. ps inspects selected processes; jobs describes jobs managed by your current shell. Start sleep 120 & and immediately assign lab_pid=$!; ps -p "$lab_pid" -o pid,ppid,stat,args shows only that practice worker. Capturing the exact PID avoids broad process matching and lets you correlate a running command with its parent, state and eventual termination evidence safely. Using a broad killall pattern can terminate unrelated work; target the PID captured from your own harmless process rather than guessed process-name matches today.

WORKED EXAMPLE
Start sleep 120 & and immediately assign lab_pid=$!; ps -p "$lab_pid" -o pid,ppid,stat,args shows only that practice worker.

Why this matters

Capturing the exact PID avoids broad process matching and lets you correlate a running command with its parent, state and eventual termination evidence safely.

A common trap

Using a broad killall pattern can terminate unrelated work; target the PID captured from your own harmless process rather than guessed process-name matches today.

Signals and graceful termination

Signals notify processes of events. SIGTERM requests termination and allows cooperative cleanup; SIGKILL forcibly stops a process and cannot be caught. Some programs use other signals for reload or interruption, but meanings depend on the program. Always verify a process before sending it a signal. kill -TERM "$lab_pid" requests termination of the captured sleep process; wait "$lab_pid" reports its completion to the shell that started it. Graceful termination gives real applications time to close files or release resources and makes forced termination a considered fallback rather than a routine habit. Starting with SIGKILL prevents cleanup and hides whether the program can stop normally; use SIGTERM first and inspect evidence before escalating a real incident.

WORKED EXAMPLE
kill -TERM "$lab_pid" requests termination of the captured sleep process; wait "$lab_pid" reports its completion to the shell that started it.

Why this matters

Graceful termination gives real applications time to close files or release resources and makes forced termination a considered fallback rather than a routine habit.

A common trap

Starting with SIGKILL prevents cleanup and hides whether the program can stop normally; use SIGTERM first and inspect evidence before escalating a real incident.

systemd units and logs

systemd manages units such as services, timers and sockets when it runs as the host’s system manager. systemctl status reports state and recent diagnostics; journalctl reads journal records. A service can be enabled for boot without being currently active, or active without being enabled. WSL requires actual systemd support and configuration. ps -p 1 -o comm= identifies PID 1; on a systemd host, systemctl list-units --type=service --state=running lists running service units. Separating startup configuration from runtime state prevents incorrect diagnoses and provides a reliable path from a failed service to its specific journal evidence today. Assuming enabled means healthy confuses boot intent with runtime behavior; inspect Active state, exit status and relevant logs before deciding the service is working.

WORKED EXAMPLE
ps -p 1 -o comm= identifies PID 1; on a systemd host, systemctl list-units --type=service --state=running lists running service units.

Why this matters

Separating startup configuration from runtime state prevents incorrect diagnoses and provides a reliable path from a failed service to its specific journal evidence today.

A common trap

Assuming enabled means healthy confuses boot intent with runtime behavior; inspect Active state, exit status and relevant logs before deciding the service is working.

KEEP THESE WITH YOU

Today’s takeaways

Capture exact process identities.

Prefer graceful termination.

Inspect runtime state independently of boot configuration.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed