home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!sun-barr!cs.utexas.edu!convex!news.utdallas.edu!corpgate!bnrgate!bcars267!bmdhh243!bnr.ca!agc
- From: agc@bnr.ca (Alan Carter)
- Subject: Re: Script for killing mutiple processes?
- Message-ID: <1992Jul21.173924.14654@bnr.uk>
- Sender: news@bnr.uk (News Administrator)
- Nntp-Posting-Host: bmdhh298
- Organization: BNR-Europe-Limited, Maidenhead, England
- References: <1992Jul21.135406.10224@ncsu.edu>
- Date: Tue, 21 Jul 1992 17:39:24 GMT
- Lines: 39
-
- In article <1992Jul21.135406.10224@ncsu.edu>, odkahn@eos.ncsu.edu (Opher D. Kahn) writes:
- |> I am working with a experimental database server that forks
- |> off child processes to serve multiple clients. However, some
- |> times these processes do not terminate correctly, and I am left
- |> with 10-15 child processes that need to be killed. Is it possible
- |> to somehow pipe the process numbers from 'ps -aux | grep dood' into
- |> a kill command, so that I don't have to kill each one of them
- |> manually??? (dood is the name of the process).
- |> Thanks,
-
- There is a general magic for this kind of thing. Bear in mind I've got System V
- type ps here, and Korn shell.
-
- 1. Get the ps output, filter out the ones that mention dood, but don't forget
- to throw away the line where dood is the argument!
-
- ps -ef | grep dood | grep -v grep
-
- 2. Now use a tool to chop out the pid field, I've used awk but cut would work.
- Check that your Berzerkely ps puts the pid on field 2, I can't remember.
-
- ps -ef | grep dood | grep -v grep | awk { print $2 }
-
- 3. Finally, do whatever you want with this stream of numbers, and chuck the
- lot through more so that you can relish the death of each. Put it in a file
- with #!/bin/ksh at the top so when it is executed the correct interpreter
- is used.
-
- #!/bin/ksh
- ps -ef | grep dood | grep -v grep | awk { print $2 } | while read var
- do
- echo "THIS IS DEATH, $var"
- kill $var
- done | more
-
- Bear in mind the dangers of letting automated kills run around on your precious
- system, and never, ever, do something like this as root.
-
- Enjoy, Alan!
-