linux/solaris 用一个命令杀死许多进程

yae*_*ael 1 linux solaris kill process shell-scripting

是否可以用一个命令杀死所有查找进程?

我不想杀死每个进程kill -9 25295,例如kill -9 11994,等等。相反,我想要的是一种简单的方法或命令来杀死所有查找进程(我的目标是在 linux 和 solaris 机器上执行此操作)。

$ ps -ef | grep find 
root 25295 25290   0 08:59:59 pts/1 0:01 find /etc -type f -exec grep -l 100.106.23.152 {} ; -print
root 11994 26144   0 09:04:18 pts/1 0:00 find /etc -type f -exec grep -l 100.106.23.153 {} ; -print
root 25366 25356   0 08:59:59 pts/1 0:01 find /etc -type f -exec grep -l 100.106.23.154 {} ; -print
root 26703 26658   0 09:00:05 pts/1 0:01 find /etc -type f -exec grep -l 100.106.23.155 {} ; -print
Run Code Online (Sandbox Code Playgroud)

kub*_*zyk 5

这将在 Linux 和 Solaris 上工作,并准确地完成您的需要:

pgrep -f 'find /etc'     # verify the listing before proceeding
pkill -9 -f 'find /etc'
Run Code Online (Sandbox Code Playgroud)

在你的情况下,避免killall. 如果您在 Linux 上使用它,迟早您会弄错 ssh 会话,在 Solaris 上运行它,从而产生不必要的风险。

所述-f的p纤ep / pkill的手段选项整个命令行匹配。如果您需要匹配程序或脚本的路径 ( /var/tmp/test.sh),如果您使用整个路径运行它,这将起作用。准确地说,你只需要逃避.所以你需要

pkill -9 -f '/var/tmp/test\.sh'

如果您运行了与./test.sh您需要杀死它相同的程序。请参阅 中的-f选项ps