One linux command per day: kill all command

Keywords: Linux shell

The killall command in Linux is used to kill processes by name. We can use Kill Command to kill the process of the specified process PID. If we want to find the process we need to kill, we also need to use ps and other commands before cooperating with grep to find the process. Kill all combines these two processes into one, which is a very useful command.

1. Command format:

killall [parameter] [process name]

2. Command function:

Used to end all processes with the same name

3. Command parameters:

  • - Z only kills processes with scontext
  • - e requires matching process names
  • - I Ignore lowercase
  • - g Kill Process Groups Instead of Processes
  • - i Interactive mode, ask the user before killing the process
  • - List all known signal names
  • - q does not output warning information
  • - s sends the specified signal
  • - v Report Signal Successfully Sended
  • - w Waiting for Process Death
  • - help displays help information
  • version Display version Display

4. Use examples:

Example 1: Kill all processes of the same name
Order:

killall vi

Output:

[root@localhost ~]# ps -ef|grep vi
root     17581 17398  0 17:51 pts/0    00:00:00 vi test.txt
root     17611 17582  0 17:51 pts/1    00:00:00 grep vi
[root@localhost ~]# ps -ef|grep vi
root     17581 17398  0 17:51 pts/0    00:00:00 vi test.txt
root     17640 17612  0 17:51 pts/2    00:00:00 vi test.log
root     17642 17582  0 17:51 pts/1    00:00:00 grep vi
[root@localhost ~]# killall vi
[root@localhost ~]# ps -ef|grep vi
root     17645 17582  0 17:52 pts/1    00:00:00 grep vi

Explain:

Example 2: Send the specified signal to the process
Order:

Background Running Program:vi&
Kill vi processes: kill all-TERM vi or kill all-KILL vi

Output:

[root@localhost ~]# vi & 
[1] 17646
[root@localhost ~]# killall -TERM vi
[1]+  Stopped                 vi
[root@localhost ~]# vi & 
[2] 17648
[root@localhost ~]# ps -ef|grep vi
root     17646 17582  0 17:54 pts/1    00:00:00 vi
root     17648 17582  0 17:54 pts/1    00:00:00 vi
root     17650 17582  0 17:55 pts/1    00:00:00 grep vi
[2]+  Stopped                 vi
[root@localhost ~]# killall -TERM vi
[root@localhost ~]# ps -ef|grep vi
root     17646 17582  0 17:54 pts/1    00:00:00 vi
root     17648 17582  0 17:54 pts/1    00:00:00 vi
root     17653 17582  0 17:55 pts/1    00:00:00 grep vi
[root@localhost ~]# killall -KILL vi
[1]-  Killed               vi
[2]+  Killed               vi
[root@localhost ~]# ps -ef|grep vi
root     17656 17582  0 17:56 pts/1    00:00:00 grep vi
[root@localhost ~]#

Explain:

Example 3: Kill all registered shell s
Order:

killall -9 bash

Output:

[root@localhost ~]# w
 18:01:03 up 41 days, 18:53,  3 users,  load average: 0.00, 0.00, 0.00USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    10.2.0.68        14:58    9:52   0.10s  0.10s -bash
root     pts/1    10.2.0.68        17:51    0.00s  0.02s  0.00s w
root     pts/2    10.2.0.68        17:51    9:24   0.01s  0.01s -bash
[root@localhost ~]# killall -9 bash
[root@localhost ~]# w
 18:01:48 up 41 days, 18:54,  1 user,  load average: 0.07, 0.02, 0.00USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    10.2.0.68        18:01    0.00s  0.01s  0.00s w
[root@localhost ~]#

Explain:

Run the command: After killall-9 bash, all bash will be blocked, so all current connections are lost. You need to reconnect and log in.

Posted by keith73 on Thu, 28 Mar 2019 06:54:29 -0700