kfork 870 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! /bin/ksh
  2. #
  3. # Shell script to kill off specified processes
  4. #
  5. # Usage: kfork <process-to-kill> <waiting time before retry>
  6. # check for the optional 3rd parameter
  7. # it will tell how long to wait before
  8. # the next kill attempt
  9. if [ $# -ge 2 ]
  10. then
  11. die_time=$2
  12. else
  13. die_time=1
  14. fi
  15. ps ${PS_ALL_FLAG} | grep $1 > /tmp/tmp.$$
  16. if [ -s /tmp/tmp.$$ ]
  17. then
  18. awk '{print "kill", $1}' /tmp/tmp.$$ | /bin/csh
  19. sleep $die_time # wait for it to die
  20. ps ${PS_ALL_FLAG} | grep $1 > /tmp/tmp.$$
  21. if [ -s /tmp/tmp.$$ ]
  22. then
  23. awk '{print "kill -3", $1}' /tmp/tmp.$$ | /bin/csh
  24. sleep $die_time # wait for it to die
  25. ps ${PS_ALL_FLAG} | grep $1 > /tmp/tmp.$$
  26. if [ -s /tmp/tmp.$$ ]
  27. then
  28. awk '{print "kill -9", $1}' /tmp/tmp.$$ | /bin/csh
  29. fi
  30. rm /tmp/tmp.$$
  31. fi
  32. if [ -f /tmp/tmp.$$ ]
  33. then
  34. rm /tmp/tmp.$$
  35. fi
  36. fi
  37. if [ -f /tmp/tmp.$$ ]
  38. then
  39. rm /tmp/tmp.$$
  40. fi