您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。