Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1890639
  • 博文数量: 389
  • 博客积分: 7877
  • 博客等级: 少将
  • 技术积分: 4521
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-10 14:02
文章分类

全部博文(389)

文章存档

2024年(1)

2022年(1)

2021年(1)

2020年(1)

2019年(1)

2018年(3)

2017年(6)

2016年(4)

2015年(8)

2014年(15)

2013年(31)

2012年(19)

2011年(47)

2010年(33)

2009年(105)

2008年(109)

2007年(4)

分类:

2009-12-17 19:42:17

杀掉给定PID进程的所有子进程,Linux下面可以通过pkill -P PID来实现,但是
AIX下面则没有pkill这个命令,网上google到了下面的脚本,可以实现这个功能:

#!/bin/ksh
# This script will kill all the child process id for a given pid
#Store the current Process ID
CURPID=$$
# This is process id, parameter passed by user
ppid=$1
if [ -z $ppid ] ; then
echo No PID given.
exit;
fi
arraycounter=1
while true
do
FORLOOP=FALSE
# Get all the child process id
for i in `ps -ef| awk '$3 == '$ppid' { print $2 }'`
do
if [ $i -ne $CURPID ] ; then
procid[$arraycounter]=$i
arraycounter=`expr $arraycounter + 1`
ppid=$i
FORLOOP=TRUE
fi
done
if [ "$FORLOOP" = "FALSE" ] ; then
arraycounter=`expr $arraycounter - 1`
## We want to kill child process id first and then parent id's
while [ $arraycounter -ne 0 ]
do
kill -9 "${procid[$arraycounter]}" >/dev/null
arraycounter=`expr $arraycounter - 1`
done
exit
fi
done
## Kill Parent ID
kill -9 $CURPID

阅读(6248) | 评论(0) | 转发(0) |
0

上一篇:google和microsoft的一个小区别

下一篇:things

给主人留下些什么吧!~~