#!/bin/sh # # beendet alle Processe mit dem angegebenem Namen und wartet eine angegebene zeit bevor die Processe engültig abgeschossen werden # proc=$1 maxwait=$(( ${2:-5} * 10 )) if [ -z "$proc" ]; then echo "usage: `basename $0` processname [max_wait]" exit 1 fi pids() { ps | grep "$1" | cut -b1-5 | while read pi; do [ $pi = $$ -o $pi = $PPID ] && break; echo $pi; done | tac } if [ $maxwait -ne 0 ]; then for pid in `pids "$proc"`; do kill $pid 2>/dev/null done i=0 while [ $i -lt $maxwait -a -n "`pids "$proc"`" ]; do i=$(( $i + 1 )) usleep 100000 done fi for pid in `pids "$proc"`; do kill -9 $pid 2>/dev/null done i=0 while [ $i -lt 50 -a -n "`pids "$proc"`" ]; do i=$(( $i + 1 )) usleep 100000 done