How to kill a running process by its name
How to kill a running process by its name?
Use the pkill command to select a running process by its name and send a kill signal.
pkill --interactive PROCESSNAMETo find running processes by their name and stop it, use the killall or pkill command.
Examples using killall
The killall command has the --interactive option that will ask a confirmation before stopping processes.
# killall -i nginx
Kill nginx(51055) ? (y/N) n
Kill nginx(60297) ? (y/N) n
Kill nginx(60298) ? (y/N) n
nginx: no process found
As we answered ’n’ to all questions, killall won’t stop any running processes.
Examples using pkill
pkill nginx
When using pkill, there is no interactive confirmation. Use the pgrep command with the -l option to confirm the right processes are targeted.
Relevant FAQ: How to show a running process name and its process ID (PID)?
Process signals
Most of the tools that can send a signal to a process or a group of processes, can be instructed to send a specific process signal. This might be useful when a process is stuck and does not respond to the default SIGTERM signal.