5+ killall Command Examples in Linux

This tutorial explains Linux “killall” command, options and its usage with examples.

killall – kill processes by name

Description :

killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent. Signals can be specified either by name (e.g. -HUP) or by number (e.g. -1).

If the command name contains a slash (/), processes executing that particular file will be selected for killing, independent of their name.

killall returns a zero return code if at least one process has been killed for each ilisted command. killall returns zero otherwise.

A killall process never kills itself (but may kill other killall processes).

advertisement
advertisement

Usage :

killall [-e,–exact] [-g,–process-group] [-i,–interactive] [-q,–quiet] [-v,–verbose] [-w,–wait] [-V,–version] [-S,–sid] [-c,–context] [-s,–signal signal] [–] name …
killall -l
killall -V,–version

Options :

-e, –exact
Require an exact match for very long names. If a command name is longer than 15 characters, the full name may be unavailable (i.e. it is swapped out). In this case, killall will kill everything that matches within the first 15 characters. With -e, such entries are skipped. killall prints a message for each skipped entry if -v is specified in addition to -e,
-g, –process-group
Kill the process group to which the process belongs. The kill signal is only sent once per group, even if multiple processes belonging to the same process group were found.
-i, –interactive
Interactively ask for confirmation before killing.
-l, –list
List all known signal names.
-q, –quiet
Do not complain if no processes were killed.
-v, –verbose
Report if the signal was successfully sent.
-V, –version
Display version information.
-w, –wait
Wait for all killed processes to die. killall checks once per second if any of the killed processes still exist and only returns if none are left. Note that killall may wait forever if the signal was ignored, had no effect, or if the process stays in zombie state.
-S
(Flask only) Specify SID: kill only processes with given SID. Mutually exclusive with -c argument. Must precede other arguments on command line.
-c
(Flask only) Specify security context: kill only processes with given security context. Mutually exclusive with -s. Must precede other arguments on the command line.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

Examples :

1. A basic example

Lets first verify that the process that we want to kill is running :

$ ps -aef | grep test
himanshu 2751 1999 0 14:00 pts/1 00:00:00 ./test
himanshu 2778 1999 0 14:01 pts/1 00:00:00 grep --colour=auto test

Now lets run the the ‘killall’ command :

advertisement
$ killall test
[1]+ Terminated ./test

As we can see above, the process ‘test’ was killed successfully. We can verify the same by running the following command again :

$ ps -aef | grep test
himanshu 2802 1999 0 14:06 pts/1 00:00:00 grep --colour=auto test

2. Direct the ‘killall’ command to ignore case

The ‘killall’ command is case sensitive. If -I is used then killall does not check the case.

advertisement
$ killall Test
Test: no process found
 
$ killall -I Test
[1]+ Terminated ./test

3. Sending different signals to kill processes

$ killall -s SIGINT test
[2]- Interrupt ./test

So we see that through the -s flag, a signal SIGINT was sent to the process.

4. To get a list of signals that killall can send, enter:

$ killall -l
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

So we see that by running killall with -l flag gets the list of all the available signals that killall can send to kill the processes.

5. Killing multiple processes interactively using -i option

$ killall -i test test1
Kill test1(3043) ? (y/N) y
Kill test(3044) ? (y/N) y
[1]- Terminated ./test1 (wd: ~/practice)
(wd now: ~)
[2]+ Terminated ./test (wd: ~/practice)
(wd now: ~)

6. Do the tasks quietly

What if a user does not want the extra information that killall command spits out in some cases like when no process matched the process name given to killall? Well, for this purpose, there exists a flag ‘-q’ that instructs killall command to keep quite wherever possible.

$ killall test test1
test: no process found
test1: no process found
$ killall -q test test1
$

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.