Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Unanswered: Free Shell script kill Zombie Processes

    Code:
    #! /bin/bash
    #
    # Zombie processes killing script. Must be run under root.
    
    case "$1" in
    --admin)
            stat=`ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"`
    
            if ((${#stat} > 0));then
                echo zombie processes found:
                echo .
                ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"
                echo -n "Kill zombies? [y/n]: "
                read keyb
                if [ $keyb == 'y' ];then
                    echo killing zombies..
                    ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print$4" status:"$10}' | grep "status:Z" | awk '{print $1}' | xargs -n 1 kill -9
                fi
            else
                echo no zombies found!
            fi
    ;;
    --cron)
            stat=`ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"`
            if ((${#stat} > 0));then
            ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print$4" status:"$10}' | grep "status:Z" | awk '{print $1}' | xargs -n 1 kill -9
            echo `date`": killed some zombie processes!" >> /var/log/zombies.log
            fi
    ;;
    *)      echo 'usage: kill-zombies {--cron|--admin}'
    ;;
    esac
    exit 0
    ----------------------------------------------------------------------
    How to using

    Thank you tips from suse.in.th

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    while it's kind of sles to post this I'll just mention that you need to have your head examined if you like to copy code of the web and run it on your server. I don't have time to check the code out. I'd suggest you look at people's post counts to get a feeling of how much trust to have.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •