home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume5 / pt.bsd / Kill next >
Encoding:
Text File  |  1989-02-03  |  2.9 KB  |  93 lines

  1. #! /bin/csh -f
  2. #
  3. #-    Kill - kill process with shell form interface
  4. #-
  5. #-    This  program will use  shell form to   display current user's
  6. #-    process  generated by  ptree command.    You  can  tab to  the
  7. #-    desired process  and select proper signal to  be  sent  to the
  8. #-    process.  Press return will trigger the action.
  9. #-
  10. #    Author:        Paul Lew, General Systems Group, Inc.
  11. #    Created at:    05/12/88  07:56 PM
  12. #    Last update:    07/26/88  10:56 AM  (Edition: 32)
  13. #
  14. #-    Usage:        Kill [string]
  15. #-    where option:
  16. #-        string    if specified, will do 'ptree ax | grep string'
  17. #-            and display only matched process.
  18. #
  19. set tmpfile = "/tmp/tmpfile.$$"
  20. set sofile = "/tmp/sofile.$$"
  21. set ptfile = "/tmp/ptfile.$$"
  22. #---------------------------------------------------------------#
  23. #          Display help if requested by user            #
  24. #---------------------------------------------------------------#
  25. switch ( "$1" )
  26.     case -H[xX]:
  27.         set echo; set verbose; shift
  28.         breaksw
  29.     case -H*:
  30.         show_help `which $0` $1
  31.         goto end
  32.     default:
  33.     endsw
  34. #---------------------------------------------------------------#
  35. #            Process Arguments            #
  36. #---------------------------------------------------------------#
  37. set greparg = '.'
  38. set ptflag = 'x'
  39. if ( "$1" != '' ) then
  40.     set greparg = $1
  41.     set ptflag = 'ax'
  42.     endif
  43. #---------------------------------------------------------------#
  44. #          Create sf description file            #
  45. #---------------------------------------------------------------#
  46. pt p$ptflag > $tmpfile
  47. tr '~' '?' < $tmpfile | sed -n \
  48.    -e '1s/COMMAND/SIGNAL &/p;1d' \
  49.    -e  '/Kill/d' \
  50.    -e "/$greparg/"'{;s/^\(..............................\)\(.*\)$/\1~~~~~~ \2/p;}' \
  51.    > $ptfile
  52. sed 's/^......//' $ptfile | colrm 80 > $tmpfile
  53. @ lcount = `cat $tmpfile | wc -l`
  54. @ lcount--
  55. if ( $lcount == 0 ) then
  56.     echo "...Pattern $greparg not found in pt list, aborted..."
  57.     goto end
  58.     endif
  59. cat << cat_eof >> $tmpfile
  60.  
  61. [TAB (next process), SPACE (next signal), - (no signal), RETURN (execute)]
  62.  
  63. cat_eof
  64. @ i = 0
  65. set sig = "/-     /HUP/INT/QUIT/ILL/TRAP/ABRT/EMT/FPE/KILL/BUS/SEGV/SYS"
  66. set sig = "$sig/PIPE/ALRM/TERM/URG/STOP/TSTP/CONT/CHLD/TTIN/TTOU/IO/XCPU"
  67. set sig = "$sig/XFSZ/VTALRM/PROF/USR1/USR2/PWR/LOST/"
  68. while ( $i < $lcount )
  69.     @ i++
  70.     echo ".v=var$i.s=$sig." >> $tmpfile
  71.     end
  72. #---------------------------------------------------------------#
  73. #           run sf to get user input            #
  74. #---------------------------------------------------------------#
  75. sf -u -o $sofile < $tmpfile
  76. if ( ! -e $sofile ) goto end
  77. source $sofile
  78. @ i = 0
  79. while ( $i < $lcount )
  80.     @ i++
  81.     set var = `eval echo \$var$i`
  82.     if ( "$var" != '-' ) then
  83.         @ line = $i + 1
  84.         kill -$var `sed -n "$line"'s/^ *\([0-9]*\).*$/\1/p' $ptfile`
  85.         endif
  86.     end
  87. #---------------------------------------------------------------#
  88. #        Clean up and exit here...            #
  89. #---------------------------------------------------------------#
  90. end:
  91.     /bin/rm -f $tmpfile $sofile $ptfile
  92.     unset tmpfile sofile ptfile i lcount var line greparg ptflag
  93.