Re: How to write a script to kill more than one process matching
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: How to write a script to kill more than one process matching




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-24-07 06: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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:43 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register