Linux Lab: Find and Kill a Process

Launch Firefox from the terminal, locate its process using multiple methods, and terminate it with kill signals.

Lab Objectives

  • Launch an application from the command line.
  • Use ps, pgrep, and top to find a running process.
  • Identify a process by its PID (Process ID).
  • Use kill and killall to terminate processes.
  • Understand different kill signals (SIGTERM vs SIGKILL).

Prerequisites

  • A Linux system with a graphical desktop (Kali, Ubuntu, etc.).
  • Firefox installed (pre-installed on most distributions).
  • Terminal access.

Part 1: Launch Firefox from the Terminal

Step 1: Open a terminal and launch Firefox in the background:
firefox &

The & runs Firefox in the background so you keep control of the terminal. Firefox should open on your desktop.

Step 2: Note the PID printed by the shell:

The number 4523 (yours will differ) is the Process ID. The shell prints this when you launch a background process.

Step 3: Verify Firefox is running:
jobs

Shows background jobs started from this terminal session. You should see Firefox listed as "Running".

Part 2: Find the Process

There are several ways to find a running process. Try each one:

Method 1: ps with grep
ps aux | grep firefox

Lists all processes, then filters for "firefox". Look at the second column — that is the PID. You may see multiple Firefox processes (one per tab).

Method 2: pgrep
pgrep firefox

Returns only the PID(s) matching the name. Cleaner than ps | grep.

Method 3: pgrep with details
pgrep -a firefox

-a shows the full command line alongside the PID.

Method 4: pidof
pidof firefox

Returns the PID(s) of a program by its exact name.

Method 5: top (interactive)
top

In top, press Shift+L and type firefox to search. The matching process will be highlighted. Press q to quit.

Method 6: Check which port Firefox is using
sudo ss -tulnp | grep firefox

Shows any network connections Firefox has open.

Part 3: Kill the Process

Step 1: Send SIGTERM (graceful shutdown) using kill:
kill $(pgrep -o firefox)

pgrep -o returns the oldest (main) Firefox PID. kill sends SIGTERM (signal 15) by default, which asks the process to shut down gracefully.

Step 2: Check if Firefox is still running:
pgrep firefox

If no output, Firefox has been terminated. If PIDs still appear, it may have ignored the signal.


If Firefox did not stop, restart it and try the next methods:

firefox &
Step 3: Use killall to kill by name:
killall firefox

Kills all processes matching the name "firefox".

Step 4: Relaunch and force kill with SIGKILL:
firefox &
kill -9 $(pgrep -o firefox)

-9 sends SIGKILL, which forcefully terminates the process. The process cannot catch or ignore this signal. Use only when SIGTERM fails.

Step 5: Verify it is gone:
pgrep firefox
ps aux | grep firefox

No Firefox processes should remain. The only match from grep will be the grep command itself.

Deliverables

  • Screenshot of firefox & showing the PID output.
  • Screenshot of ps aux | grep firefox showing the process details.
  • Screenshot of pgrep -a firefox output.
  • Screenshot of kill followed by pgrep firefox confirming termination.
  • Screenshot of kill -9 force kill.
  • A short written answer: What is the difference between SIGTERM and SIGKILL, and when would you use each?

Process Commands

  • ps aux — List all processes.
  • pgrep name — Find PID by name.
  • pgrep -a name — PID + full command.
  • pidof name — PID by exact name.
  • top — Interactive process monitor.
  • jobs — Background jobs in current shell.

Kill Commands

  • kill PID — Send SIGTERM (graceful).
  • kill -9 PID — Send SIGKILL (force).
  • killall name — Kill all by name.
  • pkill name — Kill by pattern match.

Common Signals

  • 1 (SIGHUP) — Reload configuration.
  • 2 (SIGINT) — Interrupt (Ctrl+C).
  • 9 (SIGKILL) — Force kill (cannot be caught).
  • 15 (SIGTERM) — Graceful termination (default).
  • 19 (SIGSTOP) — Pause the process.
  • 18 (SIGCONT) — Resume a paused process.

View all signals: kill -l