
Starting and controlling jobs
A shell job can run in the foreground or background. Foreground jobs attach to the terminal and block it, while background jobs run asynchronously. Common job-control actions:
Tip: Use job IDs (
%1, %2, …) when using fg/bg. Use jobs -l to map job IDs to PIDs.
Use
jobs -l when you need the PID to send signals (for example with kill). Job IDs (like %1) are shell-local; PIDs are system-wide.Sending signals with kill
Processes respond to signals (e.g., to stop, continue, or terminate). Usekill to send a signal to a PID.
kill <pid>sends SIGTERM (15) by default — a polite request to terminate.kill -9 <pid>sends SIGKILL (9) — forces immediate termination; cannot be caught or ignored.kill -llists signal names/numbers available on the system.
Example: listing signals and using
kill:
Use
kill -9 (SIGKILL) only when necessary — it prevents the process from cleaning up temporary files or gracefully closing resources. Try kill (SIGTERM) first.Killing multiple processes by name
To send a signal to all processes that match a command name, usekillall <name>. This sends the default signal (SIGTERM) to every matching process name.
Example:
killall sleep, all running sleep processes are terminated.
Using top to send signals interactively
Interactive process viewers liketop let you send signals without leaving the tool.
- While
topis running, presskto prompt for a PID and a signal number or name. - Enter the PID, then the signal (e.g.,
9orSIGKILL) to send it.
top snapshot (when k is used you are prompted for a PID and a signal):
Quick reference
Summary
- Use shell job control (Ctrl+Z,
fg,bg,jobs) to pause and resume tasks without killing them. - Prefer
kill <pid>(SIGTERM) so processes can terminate gracefully; usekill -9(SIGKILL) as a last resort. - Use
killallto target processes by name when appropriate. - Interactive tools like
topprovide convenient ways to inspect processes and send signals. - For more details, see the bash job control documentation and the
killandtopman pages: