home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!wupost!uwm.edu!caen!uvaarpa!murdoch!fulton.seas.Virginia.EDU!tdh6t
- From: tdh6t@fulton.seas.Virginia.EDU (Todd #$%!@! Hodes)
- Subject: *** Simple batch-style Unix question <<Answer Summary>>
- Message-ID: <1992Dec15.063643.15318@murdoch.acc.Virginia.EDU>
- Followup-To: sender
- Sender: usenet@murdoch.acc.Virginia.EDU
- Organization: University of Virginia
- Date: Tue, 15 Dec 1992 06:36:43 GMT
- Lines: 36
-
- I asked about a week ago about how to correct the
- following call:
-
- >ps -aux | grep "xv " | sort -2 | awk '{if (NR == 1) print $2;}' | kill -9
- >fails on the last pipe (the kill)
-
- The most common (and obvious) solution is to back-quote the pid to be
- sent to the kill, i.e.:
-
- kill -9 `ps -aux | grep "xv " | sort -2 | awk '{if (NR == 1) print $2;}'`
-
- Another solution is to use the "xargs" command:
-
- ps -aux | grep "xv " | sort -2 | awk '{if (NR == 1) print $2;}' | xargs kill -9
-
-
- Two "problems" with my approach were noted:
-
- 1) The grep will pick up another users xv call, or the "grep xv" call
- itself.
-
- 2) kill -9 should only be used if absolutely necessary; it doesn't
- allow a program to do any "clean-up" it may need to do.
-
- Both are absolutely valid points, but are easily handled by changing
- the grep to check for uid & avoid itself, and by changing the kill
- argument to a "nicer" one.
-
- Thanks to all who replied,
-
- T.
- --
- Louder Tunes == Better Code
-
- __|| __|| Todd Hodes
- (____(____) tdh6t@virginia.edu
-