您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關(guān)Shell中怎么查殺子進(jìn)程和僵尸進(jìn)程,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
代碼如下:
#!/bin/sh
# 遞歸找到導(dǎo)致進(jìn)程僵死的最底層子進(jìn)程并殺除.
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中怎么查殺子進(jìn)程和僵尸進(jìn)程,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。