Chinaunix

标题: lsof和kill命令配合使用的问题 [打印本页]

作者: showrun    时间: 2006-06-22 11:03
标题: lsof和kill命令配合使用的问题
在看lsof使用的技巧时,看到
lsof -t `which httpd`
可以得到访问httpd文件的所有进程的PID号码。他的方便之处是可以和Kill命令配合,把访问httpd文件的所有进程都kill掉。但是我试了多种方式也没有实现。请问该命令怎么写。
作者: 寂寞烈火    时间: 2006-06-22 11:07
try:

  1. kill -9 $(lsof -t $(which httpd))
复制代码

作者: showrun    时间: 2006-06-22 11:16
惯用了,谢谢
正在整理一些lsof的使用技巧方面的东西,等整理完了首发该论坛!呵呵

另外我试着编了一个脚本去做这件事情,但是没有实现,在帮忙看看(无奈)
#/bin/sh

filename=httpd
pss=`lsof -t `which $filename``

for ps in $pss
do
echo killing $ps
kill -9 $ps
done

##############

执行的结果为没有任何输出
作者: 寂寞烈火    时间: 2006-06-22 11:35
按下回车
另:
pss=`lsof -t `which $filename``
换成
pss=$(lsof -t $(which $filename))
可读性比较好而且可以避免某些意外的发生
作者: showrun    时间: 2006-06-22 13:41
谢谢法王




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2