Welcome to github.com/hsfxuebao/j… , hope to help you, if you feel ok, please click on the Star
The killall command in Linux is used to kill processes by name. We can use the kill command to kill the process specified PID. To find the process we need to kill, we need to use ps and other commands together with grep to find the process, and killall combines these two processes into one, which is a very useful command.
1. Command format:
Killall [parameter][process name]
2. Run the following command:
Used to end all processes of the same name
3. Command parameters:
-z kills only processes that have sContext
-e Requires a matching process name
-i ignores lowercase
-g Kills the process group instead of the process
-i In interactive mode, the user is asked before killing the process
-l Lists all known signal names
-q Displays no warning information
-s Sends the specified signal
-v Reports whether the signal is successfully sent
-w The waiting process dies
–help Displays help information
–version Displays the version
4. Example:
Example 1: Kill all processes with the same name
Command:
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 viCopy the code
Description:
Example 2: Sending the specified signal to the process
Command:
Background running program: vi &
To KILL the VI process, run killall-term vi or killall-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 ~]#Copy the code
Description:
Example 3: Kill all logged shells
Command:
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.0s 0.00s w root PTS /2 10.2.0.68 17:51 9:24 0.01s 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 ~]#Copy the code
Description:
After running killall-9 bash, all bash is blocked, so all current connections are lost. You need to reconnect and log in.
From:
One Linux command per day (43) : killall command