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

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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