Linux command
pkill 命令
文本
权限或系统影响较大,执行前请核对目标。
常用示例
Kill all processes
pkill [process_name]
Kill processes with exact name match
pkill -x [exact_name]
Kill processes owned by a specific user
pkill -u [username] [process_name]
Send a specific signal
pkill -[SIGTERM] [process_name]
Kill processes matching a pattern
pkill -i [pattern]
Kill the most recently started
pkill -n [process_name]
Kill the oldest
pkill -o [process_name]
说明
pkill sends signals to processes based on their names and other attributes. Unlike kill which requires process IDs, pkill uses pattern matching to identify target processes, making it more convenient for common process management tasks. By default, pkill sends SIGTERM (signal 15) to terminate processes gracefully. The pattern is matched against the process name (the executable name), but with -f it matches against the full command line including arguments. The command is particularly useful in scripts and for quickly terminating processes without first looking up their PIDs using ps or pgrep. Multiple selection criteria can be combined to precisely target specific processes.
参数
- - _signal_, --signal _signal_
- Signal to send (default: SIGTERM). Can be name or number
- -f, --full
- Match against the full command line, not just process name
- -x, --exact
- Require exact match of the process name
- -n, --newest
- Select only the most recently started matching process
- -o, --oldest
- Select only the oldest matching process
- -P _ppid_, --parent _ppid_
- Match only processes whose parent is specified
- -u _euid_, --euid _euid_
- Match only processes with specified effective user ID
- -U _uid_, --uid _uid_
- Match only processes with specified real user ID
- -g _pgrp_, --pgroup _pgrp_
- Match only processes in specified process group
- -G _gid_, --group _gid_
- Match only processes with specified real group ID
- -t _term_, --terminal _term_
- Match only processes on specified terminal
- -i, --ignore-case
- Case-insensitive pattern matching
- -v, --inverse
- Invert matching (exclude matched processes)
FAQ
What is the pkill command used for?
pkill sends signals to processes based on their names and other attributes. Unlike kill which requires process IDs, pkill uses pattern matching to identify target processes, making it more convenient for common process management tasks. By default, pkill sends SIGTERM (signal 15) to terminate processes gracefully. The pattern is matched against the process name (the executable name), but with -f it matches against the full command line including arguments. The command is particularly useful in scripts and for quickly terminating processes without first looking up their PIDs using ps or pgrep. Multiple selection criteria can be combined to precisely target specific processes.
How do I run a basic pkill example?
Run `pkill [process_name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does - _signal_, --signal _signal_ do in pkill?
Signal to send (default: SIGTERM). Can be name or number