Shell中怎么查杀子进程和僵尸进程-创新互联

本篇文章给大家分享的是有关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中怎么查杀子进程和僵尸进程,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。


网页题目:Shell中怎么查杀子进程和僵尸进程-创新互联
网页URL:http://bzwzjz.com/article/dijscj.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站制作 成都网站设计公司 成都网站建设 成都网站制作 网站建设公司 专业网站设计 成都网站建设 成都品牌网站建设 网站建设费用 app网站建设 高端网站设计 成都网站设计 成都企业网站设计 营销网站建设 成都网站建设公司 成都网站设计制作公司 企业网站制作 手机网站建设套餐 定制网站建设多少钱 阿坝网站设计 成都网站设计 成都网站建设