KILL Linux processes!! (also manage them) // Linux for Hackers // EP 7
Based on NetworkChuck's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
Use `ps -u <username>` (or `ps aux`) to see processes beyond what the current terminal is running.
Briefing
Linux process management boils down to three practical moves: find the right process, choose whether to stop it or kill it, and control whether it runs in the foreground or background. The episode’s core workflow is command-line driven—start an app (like Firefox), inspect running processes with `ps`, locate the target process ID (PID), then terminate it with `kill` (or the convenience variants) when it freezes or misbehaves.
The session begins by launching Firefox and using `ps` to list processes. A plain `ps` only shows what’s running in the current terminal context (often the shell and the `ps` command itself), so the guide switches to `ps -u <username>` to filter by the current user. To quickly narrow results, it pipes output through `grep` (described as “global regular expression print”), for example filtering for “Firefox.” The key takeaway is that process visibility depends on the exact `ps` options—without them, the terminal can mislead you into thinking nothing else is running.
When a program stalls, the episode focuses on termination. The default `kill` command requires a PID, not a name, so the workflow becomes: use `ps` + `grep` to find the PID, then run `kill <PID>`. For faster PID lookup by name, it introduces `pgrep Firefox`, which returns the PID directly. With that, killing becomes straightforward: `kill <PID>` for a targeted stop, or `kill -9 <PID>` for a forceful termination.
The episode also maps common `ps` usage patterns. It highlights `ps -aux` as a go-to command for “all users” and broad visibility, then again suggests piping to `grep` to find a specific program. For live monitoring, it demonstrates `top` (CPU-sorted process view) and `htop` (a more interactive, visually “cooler” alternative). Exiting `top`/`htop` is done with `q`.
A major portion then distinguishes foreground vs. background jobs. A foreground example uses `ping -c 100 networkchuck.com`, which occupies the terminal until completion or interruption. Stopping it uses `Ctrl+C`. To demonstrate job control, it uses `Ctrl+Z` to suspend a running foreground job, then lists jobs with `jobs`. From there, `bg` resumes suspended jobs in the background, while `fg` brings them back to the foreground—after which `Ctrl+C` can stop them again. It also shows how to run multiple jobs (multiple `ping` and `sleep` commands), suspend them, and selectively resume/kill them by job number.
Finally, the episode drills into kill signals. It explains that `kill` without a specified signal sends `SIGTERM` (signal 15), which is a polite request to terminate. It connects terminal shortcuts to signals: `Ctrl+Z` corresponds to `SIGTSTP` (signal 19, stop), and `Ctrl+C` corresponds to `SIGINT` (signal 2, interrupt). For “no questions asked” termination, it uses `kill -9` (`SIGKILL`, signal 9). It also introduces `pkill -9 <name>` to kill all processes matching a name in one shot—demonstrated by killing multiple `ping` processes at once.
Overall, the episode matters because these commands form the backbone of troubleshooting on Linux: when something hangs, the fastest path is to identify the PID, pick the right signal (polite vs. forceful), and use job control to keep the terminal usable while processes run.
Cornell Notes
Linux process management centers on three tasks: inspect running processes, control job placement (foreground/background), and terminate misbehaving programs. `ps` is used to list processes, often with `ps -u <username>` or `ps aux`, and `grep` filters results; `pgrep <name>` returns PIDs directly. To stop or kill, `kill` sends signals—default `SIGTERM` (15) is polite, while `kill -9` sends `SIGKILL` (9) to force termination. Job control uses `Ctrl+Z` to suspend, `jobs` to list, `bg` to resume in the background, and `fg` to return to the foreground, after which `Ctrl+C` can interrupt. Monitoring tools like `top` and `htop` help spot CPU-heavy processes in real time.
Why does `ps` sometimes fail to show an app like Firefox even when Firefox is running?
What’s the fastest way to kill a process when you know its name but not its PID?
How do foreground and background jobs differ in what you can do with the terminal?
What do `Ctrl+Z` and `Ctrl+C` map to in terms of signals?
When should `kill -9` be used instead of plain `kill`?
How can you kill multiple processes by name at once?
Review Questions
- When would `ps -u <username> | grep <program>` be more reliable than a plain `ps`?
- What sequence of commands moves a suspended job from background back to a state where `Ctrl+C` can stop it?
- What’s the practical difference between `kill` (default `SIGTERM`) and `kill -9` (`SIGKILL`) for a frozen application?
Key Points
- 1
Use `ps -u <username>` (or `ps aux`) to see processes beyond what the current terminal is running.
- 2
Filter process lists with `grep`, or skip filtering by using `pgrep <name>` to get a PID directly.
- 3
Terminate a process with `kill <PID>`, and force termination with `kill -9 <PID>` when it won’t respond.
- 4
Use job control for responsiveness: `Ctrl+Z` suspends, `jobs` lists, `bg` resumes in the background, and `fg` returns to the foreground.
- 5
Map shortcuts to signals: `Ctrl+Z` sends `SIGTSTP` (19) and `Ctrl+C` sends `SIGINT` (2).
- 6
Monitor system load and hotspots with `top` (CPU-sorted) or `htop` (interactive view).
- 7
Kill by name in bulk with `pkill -9 <name>` instead of collecting multiple PIDs manually.