I am a new Linux and Unix user and sysadmin. How do I kill processes by name instead by PID on Linux or Unix-like systems?
The kill command kills process by PID (process ID). To kill process by name, use killall command.[donotprint]
killall command details | |
---|---|
Description | Kill processes by name |
Category | N/A |
Difficulty | Easy |
Root privileges | No |
Estimated completion time | 10m |
- Linux
- Apple OS X Unix
- FreeBSD
Purpose
Kill process or commands by name on Linux/FreeBSD/Apple OS X Unix.
Syntax
The basic syntax is as follows:
killall process
OR
killall -SIGNAL process
OR
killall command
OR
killall -15 command
OR
killall -u {userName} processName
OR
killall -t {ttyName} processName
OR
killall [options] processName
Understanding Linux and Unix signals
To display list of all known signal names, enter:
$ killall -l
Sample outputs:
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS UNUSED
By default SIGTERM/TERM (15) is sent to process, if not signal is given to the killall command. The following signals are usefully used by both users and sysadmins:
Signal name | Numeric value | Description |
---|---|---|
SIGHUP HUP |
1 | Hangup detected on controlling terminal. Use this to reload server after updating its config files. |
SIGINT INT |
2 | Interrupt from keyboard. |
SIGQUIT QUIT |
3 | Tell command to quit. |
SIGKILL KILL |
9 | Kill running process. This single cannot be blocked by process and must be used as a last resort to kill process. The KILL signal doesn’t allow a process to exit gracefully. |
SIGTERM TERM |
15 | Kill running process gracefully i.e. close all files and exit cleanly. This is a default signal. |
SIGSTOP STOP |
19 | Stop/suspend running process. |
SIGCONT CONT |
18 | Continue process if stopped/suspended. |
You can kill your own process. To kill all other users process you need to the privileged root user.
killall command examples
In this example, start a process called xeyes as follows:
$ xeyes &
Sample outputs:
[1] 3514
To kill xeyes process, type:
$ killall xeyes
OR Send a signal as a name:
$ killall -TERM xeyes
OR send a signal numerically:
$ killall -15 xeyes
Sample outputs:
[1]+ Terminated xeyes
To get more verbose output on screen pass the -v option:
$ killall -v -TERM xeyes
Sample outputs:
Killed xeyes(4279) with signal 15 [1]+ Terminated xeyes
How do I kill process owned by the specific user?
The syntax is as follows:
killall -u {user} process
To kill php-cgi process owned by nixcraft, user:
# killall -u nixcraft php-cgi
OR
# killall -TERM -u nixcraft php-cgi
OR
# killall -KILL -u nixcraft php-cgi
How do I kill process running on specific tty?
To show the name the terminal use tty command:
$ tty
Sample outputs:
/dev/pts/0
You can also use ps command or w command to display tty:
$ ps
$ w
The syntax is as follows to kill firefox process running pts/0:
killall -t pts/0 firefox
OR
killall -t pts/0 firefox
OR
killall -t pts/0 firefox
OR combine both username and tty as follows:
# killall -u nixcraft -t pts/0 firefox
Kill process group
In this example, kill process group called php-cgi instead of process name:
$ sudo killall -KILL -v -g php-cgi
Sample outputs:
Confirm process killing
The killall command can ask for interactive confirmation before killing process by passing the -i option as follows:
$ killall -i gedit
Sample outputs:
Kill process by given time
Pass the -y TIME option to kill processes younger than given TIME. Pass the -o TIME option to kill processes older than given TIME. TIME can be expressed in the following float format then the unit:
- s for seconds
- m for minutes
- h for hours
- d for days
- w for weeks
- M for Months
- y for years
Here are some examples for timely process killing:
# Kill firefox command younger than 3 days killall -y 3d firefox # Kill top command younger than 2 minutes killall -y 2m firefox # Kill perl-cgi command older than 1 months killall -o 1M perl # Kill nginx server older than 2 years killall -o 2y nginx # Kill ping command older than 2 weeks with confirmation and owned by vivek user killall -u vivek -i -o 2w ping
killall command options
From the killall(1) command man page:
Option | Meaning |
---|---|
-e | Require exact match for very long names. |
-I | Case insensitive process name match. |
-g | Kill process group instead of process. |
-y | Kill processes younger than TIME. |
-o | Kill processes older than TIME. |
-i | Ask for confirmation before killing. |
-l | List all known signal names. |
-q | Don’t print complaints. |
-r | Interpret NAME as an extended regular expression. |
-s | Send this signal instead of SIGTERM. |
-u | Kill only process(es) running as USER. |
-v | Report if the signal was successfully sent. |
-V | Display version information. |
-w | Wait for processes to die. |
Related media
This tutorial is also available in a quick video format:
See also
- killall(1) Linux/Unix command man page
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |