Solaris killing process in bulk

[Update: 26-Nov-2010]: Commands pgrep and pkill do exactly the same in a more easier way. Refer here

Some times I am forced to kill a process due to various reasons. Most of the times, it won’t be a single process, it will be a group of process with the same name. Say like you want to kill all the java process running on your system. The nasty way is to check all the process Id of the java process, using ‘ps –ef | grep java’ then doing kill -9 <process ID>, for each process (if there is no parent process).

This would be a hectic/boring job. I usually say to myself, “Automate all your boring job”. So as usual I am digging in to Google to find one. Really I don’t find a one for Solaris systems. For Linux I came across http://ulyssesonline.com/2008/07/30/linux-kill-command/ , make sure you read it to have more understanding of the problem.

But unfortunately none of the of the Solaris releases has ‘pidof’ as a default command. Also I am not sure of the package that needs to be installed to get this utility. With help of some of my colleagues I ended up with this command ps -ef | grep <processname>  | awk ‘{print $2}’ | xargs kill -9. Quite useful, and solves my boring work. Hope the same for you too.

Note: Have to replace <processname> with the name of process that you want to kill, for example java

I am downloading Netbeans now, as you know I moved to Eclipse, and don’t have even an NetBeans installableL. Hoping my next blog will be on Java and Netbeans has to play a key role in it. Let’s wait for it!!

Advertisements

3 Responses

  1. Did you try pgrep and pkill commands in Solaris?

    I think those commands do exactly what you want.

  2. @Sree Pratheep I am totally unaware of this, Thanks for pointing out. Will give a try and let you know

  3. Hey @Sree !! Tried today.. it’s so simple and easy.. Thanks !! Updated the blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: