--- title: pkill โ€” Terminate processes by name date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A command that finds processes by name or pattern and safely sends signals. tags: program, Service and process management, pkill --- **๐Ÿ’ฌ "pkill command"** pkill finds processes by name pattern and sends a signal. It reduces the hassle of combining ps+kill. To avoid accidentally killing other processes, it is important to use `-f` and get into the habit of checking targets first. - **Concept**: Sends a signal to targets based on process name/command-line patterns. - **Default signal**: If not specified, requests graceful termination with SIGTERM(15). - **-f**: Searches the entire command line. - **-0**: Only checks targets without actually killing them. ## Commonly used options | Option | Description | | --- | --- | | -f | Finds the pattern in the entire command line (without -f, only the process name is used) | | -u | Targets only processes of a specific user | | -9 | Forces termination with SIGKILL (when graceful termination fails) | | -0 | Only checks targets without sending a signal | ## 3 essential command combinations - `pgrep -af 'batch.sh'` โ€” Check targets first (safest) - `pkill -u myapp -f 'queue:work'` โ€” Terminate by specifying both user and pattern - `pkill -TERM -f 'php-fpm' && sleep 2 && pgrep -af php-fpm` โ€” Check for leftover processes after graceful termination **๐Ÿ’ฌ "Show me how to use this as a monitoring metric"** Here are common situations on live production servers, organized step by step. ### Step 1 ยท Check targets First, use pgrep to see what will be killed. ``` pgrep -af 'queue:work' ``` ### Step 2 ยท Request graceful termination Request termination with SIGTERM. ``` pkill -TERM -f 'queue:work' ``` ### Step 3 ยท Check for leftover processes If any remain, investigate the cause and consider forced termination. ``` pgrep -af 'queue:work' || echo CLEAN ``` ## How it is used in practice ### 1. Clean up stuck workers **Situation** โ€” Queue workers are piling up unresponsive, so you need to launch new workers. ``` pkill -TERM -f 'queue:work' && sleep 2 && pgrep -af 'queue:work' ``` **Result** โ€” Confirm that the workers terminated gracefully and no processes remain. **Point** โ€” Send TERM first so in-flight work finishes safely. ### 2. Only processes for a specific user **Situation** โ€” On a shared server used by multiple users, clean up only your own tasks. ``` pkill -u deploy -f 'deploy.sh' ``` **Result** โ€” Only deploy user processes are terminated, so other users are unaffected. **Point** โ€” Without -u, processes with the same name belonging to other users will also be killed. ## Things to watch out for - If you provide a short name pattern without -f, the wrong processes may match. - -9 skips cleanup work and carries a risk of data loss. - If you mistakenly terminate critical system processes (such as sshd), your connection will drop. - Always check targets with pgrep -af before executing. ## Actual execution screen This is the result of checking targets, sending a graceful termination signal, and verifying that no leftover processes remain. ![pkill command execution result: checking targets and graceful termination](https://games.aidebatehub.com/assets/pkill-demo.png) Live production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/services/pkill.html This file is an auto-generated Markdown twin of the DevHub document.