统计linux不同运行状态的进程个数及进程名

2015-01-27 0 188
统计linux不同运行状态的进程个数及进程名
#! /bin/sh

IFS_old=$IFS
IFS=$'\n'
file="zombie.txt"
num=0
proc_name=
self="cnt_zombie.sh"

while test true
do
        if [ $1 = "arm" ]
        then
                list="`ps -w|grep $2|grep -v grep|grep -v $self`"
        elif [ $1 = "pc" ]
        then
                list="`ps axu|grep -w $2|grep -v grep|grep -v $self`"
        fi

        if [ "x$list" != "x" ]
        then
                x=
                #echo "list: $list"
                #num=`echo $list|wc -l`
                #echo "num: $num"
        else
                continue
        fi

        if [ $1 = "pc" ]
        then
                pos=`ps axu|grep PID|grep -bo COMMAND|cut -d ":" -f 1`
        elif [ $1 = "arm" ]
        then
                pos=26
        fi

        num=0
        for line in $list
        do
                num=$[$num+1]
                if [ -n $proc_name ]
                then
                        proc_name="$proc_name\n\t`echo $line|cut -c $pos- `"
                else
                        proc_name="`echo $line|cut -c $pos- `"
                fi
        done

        echo -e "process conut: $num, process list:$proc_name\n" >> $file
        sleep 3
done

遇见资源网 shell 统计linux不同运行状态的进程个数及进程名 http://www.ox520.com/16832.html

上一篇: 配置iptables
常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务