Unix Programming - Re: How to write a script to kill more than one process matching

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > August 2007 > Re: How to write a script to kill more than one process matching





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: How to write a script to kill more than one process matching
Logan Shaw

2007-08-24, 1:23 am

mullin wrote:
> Let's say that have a program that will be run more than one instance
> on Solaris, how can I use "kill" command to delete them all if I'm
> using bash shell.
>
> If I run this command:
> /usr/ucb/ps -auxwww | grep app_name | cut -f1-3 -d ' '
>
> it will return something like this:
> userA: 12345
> userA: 12340
>
> where userA is the userid running the program and 2nd one is the PID.
>
> But, how can I write the sh script to kill them all?


The simplest way to modify what you've written is to do this:

/usr/ucb/ps -auxwww | grep app_name | cut -f2 -d' ' | xargs kill

However, I would avoid using /usr/ucb/ps and instead use a ps that
allows you to format the output. Then you can include (and search on)
only the fields you really want. For example:

ps -e -o pid,args | awk '/app_name/ { print $1 }' | xargs kill

- Logan
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com