如何使用Shell缉拿问题进程

http://huoding.com/2013/01/30/225


#/bin/bash

LOAD=$(awk '{print $1}' /proc/loadavg)
CPUNUM=$(grep -c processor /proc/cpuinfo)

if [ $(echo "$LOAD > $CPUNUM" | bc) = 1 ]; then
    RESULT=$(ps -eo pcpu,pmem,user,args | awk '$1 > 0' | sort -nr)
    if [ -n "$RESULT" ]; then
        echo "$RESULT" > /var/log/ps.$(date +"%Y%m%d%H%M")
    fi
fi

你可能感兴趣的:(unix)