home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / programm / 5698 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.4 KB  |  48 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!wupost!uwm.edu!caen!uvaarpa!murdoch!fulton.seas.Virginia.EDU!tdh6t
  3. From: tdh6t@fulton.seas.Virginia.EDU (Todd #$%!@! Hodes)
  4. Subject: *** Simple batch-style Unix question <<Answer Summary>>
  5. Message-ID: <1992Dec15.063643.15318@murdoch.acc.Virginia.EDU>
  6. Followup-To: sender
  7. Sender: usenet@murdoch.acc.Virginia.EDU
  8. Organization: University of Virginia
  9. Date: Tue, 15 Dec 1992 06:36:43 GMT
  10. Lines: 36
  11.  
  12.     I asked about a week ago about how to correct the
  13. following call:
  14.  
  15. >ps -aux | grep "xv " | sort -2 | awk '{if (NR == 1) print $2;}' |  kill -9
  16. >fails on the last pipe (the kill)
  17.  
  18. The most common (and obvious) solution is to back-quote the pid to be
  19. sent to the kill, i.e.:
  20.  
  21. kill -9 `ps -aux | grep "xv " | sort -2 | awk '{if (NR == 1) print $2;}'`
  22.  
  23. Another solution is to use the "xargs" command:
  24.  
  25. ps -aux | grep "xv " | sort -2 | awk '{if (NR == 1) print $2;}' | xargs kill -9
  26.  
  27.  
  28. Two "problems" with my approach were noted:
  29.  
  30. 1) The grep will pick up another users xv call, or the "grep xv" call
  31.     itself.
  32.  
  33. 2) kill -9 should only be used if absolutely necessary; it doesn't
  34.     allow a program to do any "clean-up" it may need to do.
  35.  
  36. Both are absolutely valid points, but are easily handled by changing
  37. the grep to check for uid & avoid itself, and by changing the kill
  38. argument to a "nicer" one.
  39.  
  40. Thanks to all who replied,
  41.  
  42. T.
  43. --
  44. Louder Tunes == Better Code
  45.  
  46.      __|| __||       Todd Hodes
  47.     (____(____)      tdh6t@virginia.edu
  48.