From 541b1d3ecba24f7031bbcbb5f32575210cd38ac8 Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Fri, 20 Mar 2015 13:19:52 +0100 Subject: reproducible: only kill parentless processes if they are older than a day --- bin/reproducible_maintainance.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'bin') diff --git a/bin/reproducible_maintainance.sh b/bin/reproducible_maintainance.sh index a473da17..d0026e40 100755 --- a/bin/reproducible_maintainance.sh +++ b/bin/reproducible_maintainance.sh @@ -113,19 +113,25 @@ RESULT=$(mktemp) PBUIDS="1234 1111 2222" ps axo pid,user,size,pcpu,cmd > $HAYSTACK for i in $PBUIDS ; do - for ZOMBIE in $(pgrep -u $i -P 1 || true) ; do + for PROCESS in $(pgrep -u $i -P 1 || true) ; do # faked-sysv comes and goes... - grep ^$ZOMBIE $HAYSTACK | grep -v faked-sysv >> $RESULT 2> /dev/null || true + grep ^$PROCESS $HAYSTACK | grep -v faked-sysv >> $RESULT 2> /dev/null || true done done if [ -s $RESULT ] ; then echo - echo "Warning: processes found which should not be there, killing them now:" + echo "Warning: processes found which should not be there, maybe killing them now:" cat $RESULT echo - ZOMBIES=$(cat $RESULT | cut -d " " -f1 | xargs echo) - sudo kill -9 $(echo $ZOMBIES) 2>&1 - echo "'kill -9 $(echo $ZOMBIES)' done." + for PROCESS in $(cat $RESULT | cut -d " " -f1 | xargs echo) ; do + AGE=$(ps -p $PROCESS -o etimes= || echo 0) + if [ $AGE -gt 86400 ] ; then + sudo kill -9 $PROCESS 2>&1 + echo "'kill -9 $PROCESS' done." + else + echo "Did not kill $PROCESS as it is only $AGE seconds old." + fi + done echo DIRTY=true fi -- cgit v1.2.3-70-g09d2