在脚本中显示进程并杀死的方法

作者在 2011-12-26 13:17:30 发布以下内容
可以写入脚本中干掉进程等方法一:
核实获取到的id号,以核实是否正确
[root@f5ha.com ~]# ps -ef |grep -v 'grep '| grep httpd  | awk '$3 ~ /[0-9]+/ {print $3}' | while read s; do echo $s; done
核实后杀掉进程即可
[root@f5ha.com ~]# ps -ef |grep -v 'grep '| grep httpd  | awk '$3 ~ /[0-9]+/ {print $3}' | while read s; do kill -9  $s;  done方法二:
核实获取到的id号,以核实是否正确
[root@f5ha.com ~]# ps axu |grep -v 'grep' |egrep "httpd"|awk '{system("echo "$2)}'
核实后杀掉进程即可
[root@f5ha.com ~]# ps axu |grep -v 'grep' |egrep "httpd"|awk '{system("kill -9 "$2)}'注释:
grep -v grep(过滤掉本语句本身的进程)
这句是必须加的要不然脚本会先杀死自己,然后就不会去执行杀死其他的进程了。
基础知识 | 阅读 2403 次
文章评论,共2条
vfdff(作者)
2011-12-26 13:18
1
wmic process get processid,parentprocessid,name
vfdff(作者)
2011-12-26 13:19
2
function get_child_pids ( )<br />
{<br />
&nbsp; &nbsp; c_pid=$1<br />
&nbsp; &nbsp; while [ ! -z ${c_pid} ]; do<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;c_pids=${c_pid}&quot; &quot;${c_pids}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;c_pid=`ps -ef|awk '{print $2&quot; &quot;$3}'|grep &quot; ${c_pid}&quot;|awk '{print $1}'`<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[ -z &quot;${c_pid}&quot; ] &amp;&amp; return<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;for i in ${c_pid}; do<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;get_child_pids $i<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;done<br />
&nbsp; &nbsp; done<br />
}<br />
这其实也是用脚本写的一个递归调用实例,将$$作为这个函数的参数传入,执行完成后,${c_pids}就是所有的进程ID的列表了,包括$$
游客请输入验证码
浏览1940617次