输出所有 zombie 的进程到 zombie.txt 杀死所有 zombie 进程。

    1. #!/bin/bash
    2. ALL_PROCESS=$(ls /proc/ | egrep '[0-9]+')
    3. running_count=0
    4. stoped_count=0
    5. sleeping_count=0
    6. zombie_count=0
    7. for pid in ${ALL_PROCESS[*]}
    8. do
    9. test -f /proc/$pid/status && state=$(egrep "State" /proc/$pid/status | awk
    10. '{print $2}')
    11. case "$state" in
    12. R)
    13. running_count=$((running_count+1))
    14. ;;
    15. T)
    16. stoped_count=$((stoped_count+1))
    17. ;;
    18. S)
    19. sleeping_count=$((sleeping_count+1))
    20. ;;
    21. Z)
    22. zombie_count=$((zombie_count+1))
    23. echo "$pid" >>zombie.txt
    24. kill -9 "$pid"
    25. ;;
    26. esac
    27. done
    28. echo -e "total:
    29. $((running_count+stoped_count+sleeping_count+zombie_count))\nrunning:
    30. $running_count\nstoped: $stoped_count\nsleeping: $sleeping_count\nzombie:
    31. $zombie_count"