pkill Cheatsheet
Basic Syntax
Core pkill command forms.
| Command | Description |
|---|---|
pkill process_name |
Send SIGTERM to matching process names |
pkill -f "pattern" |
Match against full command line |
pkill -u username process_name |
Match only processes owned by a user |
pkill -x process_name |
Match exact process name only |
pkill -l process_name |
Kill matching processes and print their name and PID |
Common Signals
Frequently used signals with pkill.
| Command | Description |
|---|---|
pkill -15 process_name |
Graceful stop (SIGTERM, default) |
pkill -9 process_name |
Force kill (SIGKILL) |
pkill -HUP process_name |
Reload/reopen config for daemons |
pkill -INT process_name |
Interrupt process (SIGINT) |
pkill -USR1 process_name |
Send user-defined signal 1 |
Match Controls
Limit matches to avoid terminating the wrong process.
| Command | Description |
|---|---|
pkill -x nginx |
Kill only exact nginx process name |
pkill -f "python3 app.py" |
Match a specific command string |
pkill -u deploy -x node |
Match exact node only for user deploy |
pkill -t pts/2 |
Match processes attached to terminal pts/2 |
pkill -P 1234 |
Match child processes of PID 1234 |
Safer Workflow
Preview targets before signaling processes.
| Command | Description |
|---|---|
pgrep -a nginx |
Preview matching processes and command lines |
pgrep -afu deploy node |
Preview user-scoped full-command matches |
pgrep -f "python3 app.py" |
Confirm full-pattern matches first |
pkill -x nginx |
Execute only after preview validation |
echo $? |
Check exit code (0 match found, 1 none found) |
Service and App Examples
Practical process control patterns.
| Command | Description |
|---|---|
pkill -HUP nginx |
Ask Nginx master process to reload |
pkill -u www-data -x php-fpm |
Stop php-fpm workers for one user |
pkill -f "gunicorn: worker" |
Signal Gunicorn worker processes |
pkill -f "node server.js" |
Stop a specific Node.js app instance |
pkill -x firefox |
Close all Firefox processes for current user |
Troubleshooting
Quick checks for common pkill issues.
| Issue | Check |
|---|---|
| Nothing happened | Verify matches with pgrep -a using the same pattern |
| Wrong process was terminated | Use -x or stricter -f pattern matching |
Operation not permitted |
Use sudo or run as the process owner |
| Process did not stop | Try SIGTERM first, then escalate to -9 only if needed |
| Script fails when nothing matches | Handle exit code 1 as a non-match condition |
Related Guides
Use these guides for deeper signal and process-management workflows.
| Guide | Description |
|---|---|
| pkill Command in Linux | Full pkill guide with examples |
| kill Command in Linux | Send signals by PID |
| pgrep Command in Linux | Search processes by name and pattern |
| ps Command in Linux | Inspect current process list |
| top Command in Linux | Monitor processes in real time |
