Get AI summaries of any video or article — Sign up free
KILL Linux processes!! (also manage them) // Linux for Hackers // EP 7 thumbnail

KILL Linux processes!! (also manage them) // Linux for Hackers // EP 7

NetworkChuck·
5 min read

Based on NetworkChuck's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

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?

A plain `ps` is limited to the current terminal context, so it may only show the shell and the `ps` command itself. Filtering by user fixes this: `ps -u <username>` lists processes owned by that account. Then piping to `grep` (e.g., `ps -u <username> | grep Firefox`) isolates the Firefox process and reveals its PID.

What’s the fastest way to kill a process when you know its name but not its PID?

Use `pgrep`. For example, `pgrep Firefox` returns the PID directly. Then run `kill <PID>` to terminate it. If you need a forceful kill, use `kill -9 <PID>` (SIGKILL).

How do foreground and background jobs differ in what you can do with the terminal?

Foreground jobs tie up the terminal: while `ping -c 100 networkchuck.com` runs in the foreground, the terminal can’t be used for other commands until it finishes or is interrupted. Background jobs let the terminal keep working. Suspending with `Ctrl+Z` stops the job temporarily, `bg` resumes it in the background, and `fg` brings it back to the foreground for interaction.

What do `Ctrl+Z` and `Ctrl+C` map to in terms of signals?

`Ctrl+Z` corresponds to `SIGTSTP` (signal 19), which stops/suspends a job. `Ctrl+C` corresponds to `SIGINT` (signal 2), which interrupts the running process. The episode also notes that `kill` without a signal sends `SIGTERM` (signal 15), which is a polite termination request.

When should `kill -9` be used instead of plain `kill`?

Plain `kill` (default `SIGTERM`, 15) asks the process to terminate and it may refuse or delay if it’s stuck. `kill -9` sends `SIGKILL` (9), which forcefully terminates the process without negotiation—useful when a program is frozen or won’t respond to gentler signals.

How can you kill multiple processes by name at once?

Use `pkill`. The example uses `pkill -9 <name>` to target all processes matching that name, avoiding manual PID collection. This is demonstrated by starting multiple `ping` processes and then killing them together with `pkill -9 ping` (via the `pkill` command pattern shown).

Review Questions

  1. When would `ps -u <username> | grep <program>` be more reliable than a plain `ps`?
  2. What sequence of commands moves a suspended job from background back to a state where `Ctrl+C` can stop it?
  3. What’s the practical difference between `kill` (default `SIGTERM`) and `kill -9` (`SIGKILL`) for a frozen application?

Key Points

  1. 1

    Use `ps -u <username>` (or `ps aux`) to see processes beyond what the current terminal is running.

  2. 2

    Filter process lists with `grep`, or skip filtering by using `pgrep <name>` to get a PID directly.

  3. 3

    Terminate a process with `kill <PID>`, and force termination with `kill -9 <PID>` when it won’t respond.

  4. 4

    Use job control for responsiveness: `Ctrl+Z` suspends, `jobs` lists, `bg` resumes in the background, and `fg` returns to the foreground.

  5. 5

    Map shortcuts to signals: `Ctrl+Z` sends `SIGTSTP` (19) and `Ctrl+C` sends `SIGINT` (2).

  6. 6

    Monitor system load and hotspots with `top` (CPU-sorted) or `htop` (interactive view).

  7. 7

    Kill by name in bulk with `pkill -9 <name>` instead of collecting multiple PIDs manually.

Highlights

`pgrep Firefox` turns the “find the PID” step into a single command, making `kill` much faster.
`kill` defaults to `SIGTERM` (15), but `kill -9` uses `SIGKILL` (9) for forceful termination.
Job control is a practical workflow: `Ctrl+Z` → `jobs` → `bg`/`fg` → `Ctrl+C` when the job is back in the foreground.
`top` and `htop` provide real-time process monitoring, with `top` sorting by CPU usage.
`pkill -9 <name>` can terminate all matching processes at once, useful for cleaning up many `ping` jobs.

Topics

  • Process Discovery
  • Job Control
  • Kill Signals
  • Process Monitoring
  • Command-Line Tools

Mentioned

  • PID
  • SIGTERM
  • SIGKILL
  • SIGTSTP
  • SIGINT