vserverkillall (1752B)
1 #!/bin/sh 2 3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> 4 # based on vserverkillall by Jacques Gelinas 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; either version 2, or (at your option) 9 # any later version. 10 # 11 # This program is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public License 17 # along with this program; if not, write to the Free Software 18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20 # This script kills all process it can finds 21 # Only useful if you are using a security context. 22 # It does nothing in context 0 23 USR_LIB_VSERVER=/usr/lib/util-vserver 24 CTX=`grep ^s_context /proc/self/status | sed s/s_context:// | (read a b; echo $a)` 25 CTX=`eval expr $CTX + 0` 26 if [ "$CTX" = 0 ] ; then 27 echo Running in security context 0, do nothing 28 else 29 cd /proc 30 for SIG in -TERM -TERM -TERM -9 31 do 32 ONE=0 33 for dir in * 34 do 35 case $dir in 36 1) 37 ;; 38 $$) 39 ;; 40 [1-9]*) 41 ONE=1 42 echo kill $SIG "`$USR_LIB_VSERVER/readlink /proc/$dir/exe`"[$dir] 43 kill $SIG $dir 44 ;; 45 *) 46 ;; 47 esac 48 done 49 if [ "$ONE" = 0 ] ; then 50 break 51 fi 52 sleep 1 53 done 54 # Kill the fakeinit process. It is shown as process one, but can't 55 # be killed this way 56 INITPID=`cat /proc/self/status | grep initpid: | (read a b; expr $b)` 57 if [ "$INITPID" != "0" ] ; then 58 echo kill init, pid $INITPID 59 kill -9 $INITPID 60 fi 61 fi 62 63