home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sources / wanted / 5494 < prev    next >
Encoding:
Text File  |  1992-12-27  |  2.3 KB  |  82 lines

  1. Newsgroups: comp.sources.wanted
  2. Path: sparky!uunet!wupost!udel!rochester!rocksanne!leisner
  3. From: leisner@wrc.xerox.com ( Marty Leisner)
  4. Subject: Re: kill-by-name that *works*
  5. Message-ID: <1992Dec28.023100.22222@spectrum.xerox.com>
  6. Sender: news@spectrum.xerox.com
  7. Reply-To: leisner@eso.mc.xerox.com
  8. Organization: Xerox
  9. X-Newsreader: TIN [version 1.1 PL8]
  10. References: <1gia4iINN5t1@iraul1.ira.uka.de>
  11. Date: Mon, 28 Dec 1992 02:31:00 GMT
  12. Lines: 68
  13.  
  14. Lutz Prechelt (prechelt@i41s18.ira.uka.de) wrote:
  15. : I am looking for a program or script for Unix (namely SUN-OS and 
  16. : Ultrix, but should be portable, if possible), that
  17. : kills processes by giving the name of the program they run instead
  18. : of by giving their process number.
  19.  
  20. : I have a shell script (written myself) that works most of the time, 
  21. : but when the youngest processes do not have the highest PIDs of all
  22. : existing processes (which is possible, if a system runs long
  23. : enough and PIDs wrap around after about 30000 processes), 
  24. : it gets into trouble.
  25.  
  26. :   Lutz
  27.  
  28.  
  29. : -- 
  30. : Lutz Prechelt   (email: prechelt@ira.uka.de)            | Whenever you 
  31. : Institut fuer Programmstrukturen und Datenorganisation  | complicate things,
  32. : Universitaet Karlsruhe;  D-7500 Karlsruhe 1;  Germany   | they get
  33. : (Voice: ++49/721/608-4317, FAX: ++49/721/694092)        | less simple.
  34.  
  35. I'm using David Skoll's  (dfs@doe.carleton.ca) he bundles with remind:
  36.  
  37.  
  38. #!/bin/sh
  39. #
  40. # kall - kill all processes belonging to this user that match
  41. #           specified string.
  42.  
  43. signal=`echo $1 | grep '^\-.*'`
  44. me=`basename $0`
  45.  
  46. if [ "$signal" != "" ]; then
  47.     shift
  48. else
  49.     signal="-TERM"
  50. fi
  51.  
  52. if [ "$1" = "" ]; then
  53.     echo "usage: $me [-signal] string [string...]"
  54.     echo "       kills all of your processes where command name matches"
  55.     echo "       any of the given strings."
  56.     exit
  57. fi
  58.  
  59. msg="0"
  60.  
  61. while [ "$1" != "" ]; do
  62.  
  63. # NOTE:  You may have to modify the next line, since PS is non-portable.
  64. # The 'awk' command picks out the process IDs to pass them on to kill.
  65.     rprocs=`ps cx | awk '{if(prog == $5) print $1}' prog=$1 -`
  66.     if [ "$rprocs" != "" ]; then
  67.         msg="1"
  68.         echo -n "${me}: Sending $signal signal to $1 process(es)"
  69.         echo '...'
  70.         kill $signal $rprocs
  71.     fi
  72.     shift
  73. done
  74.  
  75. if [ $msg = "1" ]; then
  76.     echo "${me}: Done."
  77. fi
  78. --
  79. marty
  80. leisner.henr801c@xerox.com  leisner@eso.mc.xerox.com
  81. Member of the League for Programming Freedom
  82.