Linux / Unix: killall Command Examples

by on January 13, 2013 · 0 comments· LAST UPDATED February 3, 2014

in , ,

killall command

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.

Please note that killall command on AIX/Solairs/HP-UX and few other traditional Unix operating systems cancels all processes except the calling process i.e. it terminate all active processes. The command discussed here is about killing process by name and tested on the following platforms only:

  1. Linux
  2. Apple OS X Unix
  3. 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 nameNumeric valueDescription
SIGHUP
HUP
1Hangup detected on controlling terminal. Use this to reload server after updating its config files.
SIGINT
INT
2Interrupt from keyboard.
SIGQUIT
QUIT
3Tell command to quit.
SIGKILL
KILL
9Kill 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
15Kill running process gracefully i.e. close all files and exit cleanly. This is a default signal.
SIGSTOP
STOP
19Stop/suspend running process.
SIGCONT
CONT
18Continue 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:

Fig. 01: killall command in action

Fig. 01: killall command in action


The kill signal is only sent once per group, even if multiple processes belonging to the same process group were found.

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:

Animated gif 01: killall command demo

Animated gif 01: killall command demo

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:

  1. s for seconds
  2. m for minutes
  3. h for hours
  4. d for days
  5. w for weeks
  6. M for Months
  7. 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:

OptionMeaning
-eRequire exact match for very long names.
-ICase insensitive process name match.
-gKill process group instead of process.
-yKill processes younger than TIME.
-oKill processes older than TIME.
-iAsk for confirmation before killing.
-lList all known signal names.
-qDon't print complaints.
-rInterpret NAME as an extended regular expression.
-sSend this signal instead of SIGTERM.
-uKill only process(es) running as USER.
-vReport if the signal was successfully sent.
-VDisplay version information.
-wWait for processes to die.

Related media

This tutorial is also available in a quick video format:

See also
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationgroupsidlastlastcommlognameuserswwhowhoamilidmembers

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: ,

Previous Faq:

Next Faq: