Safe Kill
Posted in 1995
We have a need for a shell which we can distribute to some of our supervisors to kill processes for users who have not logged out of a database. Don't ask why, the reason is ugly. A friend of a friend picked the following shell off the network sometime ago and recommended it's use: #!/bin/sh if [ "$#" -lt 1 ] then echo " " echo "USAGE : $0 <pid list>" echo " " exit 1 fi for _pid in `echo $*` do echo $_pid for line in `tbstat -u | awk /Users/,/active/ | grep $_pid | \\ awk '{print $1"~"$2"~"$3"~" }'` do user_address=`echo $line | cut -d~ -f1` for trans in `tbstat -u | awk /Transactions/,/active/ | \\ grep $user_address | \\ awk '{print $1"~"$2"~"$3"~" }'` do trans_address=`echo $trans | cut -d~ -f1` echo "tbmode -Z $trans_address" tbmode -Z $trans_address sleep 2 echo "tbmode -z $_pid" tbmode -z $_pid done done done It appears that the shell first determines the transaction address, does a tbmode -Z on that address sleeps for 2 and then does a tbmode -z on the user process id. My questions are: 1) It appears that the author of this shell feels that if one does a tbmode -Z on a transaction, it is safe then to do a tbmode -z on the process. Is this correct? Does the tbmode -Z free latches and insure that the process is not in a critical section of code? 2) Is it *always* safe to do a tbmode -Z on a transaction if the database is not logged? Presumably from reading the Administrator's Guide, it is occasionally unsafe on a logged database in a distributed environment. 3) My testing of the shell seems to indicate that it disconnects??? the sqlturbo process, but does not kill it. Does anyone know if it is then safe to follow the final tbmode -z with a kill after sleeping - say 5 seconds? 4) If this code is not safe for use by non-dbadmins, Does anyone know of source code to a program (shells are fine) which will allow someone to safely kill a process without imposing the burden of manually checking to see if the process is in a critical section of code or holds a latch? (That is, the program checks these things and then does the kill)? 5) In case I have to write my own shell - or use one I'm not sure about, can someone tell me how to force an SQL or 4GL script into a latch long enough form me to test the kill program? Ditto with a critical section of code? Thanks in advance for your help. Tim Helton timh@amgen.com 805-447-4760 Tim Helton timh@amgen.com Amgen doesn't believe a word I say, maybe they know something you don't?