濮阳杆衣贸易有限公司

主頁 > 知識庫 > Shell腳本實現(xiàn)查殺子進(jìn)程、僵尸進(jìn)程

Shell腳本實現(xiàn)查殺子進(jìn)程、僵尸進(jìn)程

熱門標(biāo)簽:寧波智能外呼系統(tǒng)公司 地圖標(biāo)注輻射圖案 申請公司400電話要注意什么 聯(lián)通電話機(jī)器人怎么接 電銷機(jī)器人 劍魚 衛(wèi)星地圖標(biāo)注地名 曲阜400電話辦理 奧維互動地圖標(biāo)注參數(shù) 安裝外呼系統(tǒng)費(fèi)用

核心服務(wù)器上跑了一堆的腳本、程序,難免有時候會出現(xiàn)僵尸進(jìn)程,死不死活不活的在那里占用資源,最初只是寫了個根據(jù)關(guān)鍵字查殺進(jìn)程的linux shell腳本,后來發(fā)現(xiàn)很多時候進(jìn)程死在那里的時候其實是內(nèi)部調(diào)用子進(jìn)程的時候出現(xiàn)了問題,這時候光殺父進(jìn)程根本沒解決根本問題。比如說rsync的時候通過ssh來連接,rsync本身沒問題,但可能ssh死掉了。因此重新寫了腳本,遞歸查找子進(jìn)程。

復(fù)制代碼 代碼如下:

#!/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

標(biāo)簽:江西 上饒 遵義 安康 仙桃 三門峽 大慶 大興安嶺

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell腳本實現(xiàn)查殺子進(jìn)程、僵尸進(jìn)程》,本文關(guān)鍵詞  Shell,腳本,實現(xiàn),查,殺子,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Shell腳本實現(xiàn)查殺子進(jìn)程、僵尸進(jìn)程》相關(guān)的同類信息!
  • 本頁收集關(guān)于Shell腳本實現(xiàn)查殺子進(jìn)程、僵尸進(jìn)程的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    南宫市| 宜川县| 文昌市| 称多县| 青海省| 嵊泗县| 都兰县| 万宁市| 建昌县| 金塔县| 化州市| 长岛县| 萨嘎县| 伊川县| 理塘县| 吴桥县| 吉林省| 奉新县| 德庆县| 剑阁县| 阿瓦提县| 乌鲁木齐县| 山丹县| 通州区| 无极县| 鸡泽县| 阿瓦提县| 柏乡县| 麟游县| 南充市| 宜阳县| 双牌县| 定州市| 弥勒县| 诸城市| 北票市| 名山县| 沈阳市| 日照市| 娄底市| 中方县|