home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.wanted
- Path: sparky!uunet!wupost!udel!rochester!rocksanne!leisner
- From: leisner@wrc.xerox.com ( Marty Leisner)
- Subject: Re: kill-by-name that *works*
- Message-ID: <1992Dec28.023100.22222@spectrum.xerox.com>
- Sender: news@spectrum.xerox.com
- Reply-To: leisner@eso.mc.xerox.com
- Organization: Xerox
- X-Newsreader: TIN [version 1.1 PL8]
- References: <1gia4iINN5t1@iraul1.ira.uka.de>
- Date: Mon, 28 Dec 1992 02:31:00 GMT
- Lines: 68
-
- Lutz Prechelt (prechelt@i41s18.ira.uka.de) wrote:
- : I am looking for a program or script for Unix (namely SUN-OS and
- : Ultrix, but should be portable, if possible), that
- : kills processes by giving the name of the program they run instead
- : of by giving their process number.
-
- : I have a shell script (written myself) that works most of the time,
- : but when the youngest processes do not have the highest PIDs of all
- : existing processes (which is possible, if a system runs long
- : enough and PIDs wrap around after about 30000 processes),
- : it gets into trouble.
-
- : Lutz
-
-
- : --
- : Lutz Prechelt (email: prechelt@ira.uka.de) | Whenever you
- : Institut fuer Programmstrukturen und Datenorganisation | complicate things,
- : Universitaet Karlsruhe; D-7500 Karlsruhe 1; Germany | they get
- : (Voice: ++49/721/608-4317, FAX: ++49/721/694092) | less simple.
-
- I'm using David Skoll's (dfs@doe.carleton.ca) he bundles with remind:
-
-
- #!/bin/sh
- #
- # kall - kill all processes belonging to this user that match
- # specified string.
-
- signal=`echo $1 | grep '^\-.*'`
- me=`basename $0`
-
- if [ "$signal" != "" ]; then
- shift
- else
- signal="-TERM"
- fi
-
- if [ "$1" = "" ]; then
- echo "usage: $me [-signal] string [string...]"
- echo " kills all of your processes where command name matches"
- echo " any of the given strings."
- exit
- fi
-
- msg="0"
-
- while [ "$1" != "" ]; do
-
- # NOTE: You may have to modify the next line, since PS is non-portable.
- # The 'awk' command picks out the process IDs to pass them on to kill.
- rprocs=`ps cx | awk '{if(prog == $5) print $1}' prog=$1 -`
- if [ "$rprocs" != "" ]; then
- msg="1"
- echo -n "${me}: Sending $signal signal to $1 process(es)"
- echo '...'
- kill $signal $rprocs
- fi
- shift
- done
-
- if [ $msg = "1" ]; then
- echo "${me}: Done."
- fi
- --
- marty
- leisner.henr801c@xerox.com leisner@eso.mc.xerox.com
- Member of the League for Programming Freedom
-