[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: grepping in ps output

On Fri, Apr 28, 2000 at 07:39:37PM -0400, B.C.J.O wrote:
> Evi Nemeth had a good trick for dealing with  that situation using the
> short test notation:
> f'rinstance, you want to nuke every process owned by user:
> kill -9 `ps aux | grep [u]ser | awk '{print $2}'`
> ... where the trick is obviously the square brackets around the first
> letter in the username, testing for the existence of that letter in the
> grep output. This prevents the grep from being killed off before the
> command can complete.

Actually all it does is prevent kill from trying to kill a non-existant
(or entirely new, but that's unlikely) process.  The "ps aux" pipeline,
including the grep, will have finished before "kill -9" starts, since
kill needs the output for its command line args.

Neat trick though.  I'll have to remember that.

- Chris

Reply to: