本篇文章给大家分享的是有关Shell中怎么查杀子进程和僵尸进程,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
代码如下:
#!/bin/sh
# 递归找到导致进程僵死的最底层子进程并杀除.
ParentProcessID=$1;
if [ "x${ParentProcessID}" = "x" ] ; then
echo "Please Supply the top Parent Process ID to be killed!"
echo "Usage:sh $0 PID [-v]"
echo "PID The Parent Process ID as root"
echo "-v is this argument supplied,no real kill operation will be performed,only process tree be show."
exit 1
fi
let IsRealKillDo=1;
if [ "x$2" = "x-v" ] ; then
let IsRealKillDo=0;
fi
echo "Begin Kill the Leaf Process of process ${ParentProcessID}" >&2
killpidList=""
function loopNextSubProcess(){
local nParentProcessID=$1
local tmpPidList=""
tmpPidList=`ps -A --format='%p%PisParent' --width 2048 -w --sort pid|grep "${nParentProcessID}isParent"|grep -v grep|grep -v "$$" | awk '{ printf $1 }'`
ps --format='%p%P%a' --width 2048 -w -p ${nParentProcessID}|grep -v grep|grep -v "$$" >&2
if [ "x${tmpPidList}" = "x" ] ; then
echo "****Got One Leaf = [${nParentProcessID}]****" >&2
killpidList="${killpidList}\n${nParentProcessID}"
return
fi
for theNextPid in ${tmpPidList} ; do
loopNextSubProcess ${theNextPid}
done
}
loopNextSubProcess ${ParentProcessID}
if [ ${IsRealKillDo} -eq 1 -a "x${killpidList}" != "x" ] ; then
for curpid in `echo -e ${killpidList}` ; do
if [ "x${curpid}" != "x" ] ; then
echo "kill -9 ${curpid}"
kill -9 ${curpid}
fi
done
else
echo -e ${killpidList}
fi
以上就是Shell中怎么查杀子进程和僵尸进程,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。