Scripting

Really Kill

(:source) #!/bin/sh # # $Id: reallykill,v 1.2 2004/10/11 09:36:48 jmates Exp $ # # The author disclaims all copyrights and releases this script into the # public domain. # # Kills the specified processes by starting with the TERM signal and # only if necessary working up to the violent KILL signal. For more # information, see: # # http://sial.org/howto/shell/kill-9/ if [ -z "$1" ]; then echo "usage: `basename $0` pid [pid ..]" >&2 exit 100 fi cycle_kill () { PID=$1 RETVAL=0 for signal in "TERM" "INT" "HUP" "KILL"; do kill -$signal $PID RETVAL=$? [ $RETVAL -eq 0 ] && break echo "warning: kill failed: pid=$PID, signal=$signal" >&2 sleep 1 done return $RETVAL } for pid in "$@"; do cycle_kill $pid done