Awk:

ps aux | grep xxx | awk '{print("kill "$2)}' | /bin/sh

The last part is to execute it otherwise it just prints it to screen.

There are other ways; I happen to like awk because you can "prototype" the
command. Then, when you have it *just* right, you can add the | /bin/sh at
the end. :)

On Fri, 26 Feb 1999, Dan Browning (Network Admin) wrote:

> I need to be able to kill a parent process based on the child process name.
> I can use "ps aux | grep xxx" to find the parent parent process ID - but how
> do I get that number out of that line?  I need to pipe that number to kill,
> so that the parent is dead and all it's children die.  I tried to pipe it to
> cut, but I couldn't get it work every time.   Or maybe there is a command
> that reports the parent of a process?  That would be the handiest.
> 
> Some more background info:
> 
> Thanks to your guys' help, I have a simple script (included below), that
> just runs a few programs in a loop for me.  But the parent of the process
> is -bash.  The problem is when I want to stop the mirror program.  Of course
> I can't just "killall mirror" because the shell will just start another one
> (because of the loop).  Now, because the parent is bash, then I would have
> to kill all bash processes (assuming I don't know which bash started my
> "mirror"s) to get the child processes (mirror) to stop.
> 
> Is there a command that will return the name of the parent of a given
> process?  Then I could pipe that to killall.
> 
> Here is the contents of the file newmirrormandrake.sh
> ----------------------------
> M=/home/danb/mirror/mirror.mandrake
> 
> while true
> do
>       mirror -pMandrake       $M
>       mirror -papps           $M
>       mirror -pdoc            $M
>       mirror -pdosutils       $M
>       mirror -pimages                 $M
>       mirror -pmisc           $M
> done
> ----------------------------
> 
> TIA.
> 
> 
> Dan Browning
> Network Administrator
> Cyclone Computer Systems
> 

_Deirdre  *  http://disclaimer.deirdre.org  *  http://www.deirdre.net
"I would rather choose to have my leg bitten off than to buy NT"
Rob Narberes, Information Systems Manager, DNA Plant Technologies Corp
as quoted in (!) Computerworld

Reply via email to