Set the process title for java app in Linux

So I start up a java application in Linux, and get something like this from `pstree`:

     |-java---java---5*[java]

Which is all fine until I start up a bunch of apps...

     |-java---java---5*[java]
     |-java---java---3*[java]
     |-java---java---2*[java]
     |-java---java---5*[java]
     |-java---java---7*[java]
     |-java---java---4*[java]

Now I want to know if a certain app is running, or maybe kill a misbehaving one...not so clear which is which.  Yeah, I could use `ps aux | grep ...` and I might be able to narrow down a process which belongs to that app and go from there.  However even that is a mess with a ton of lines like:

javauser 25635  0.1  2.5 1802196 52688 pts/2   Sl   11:16   0:03 java -server -Xms16m -Xmx16m -Djava.security.policy=/blah/ -Djava.endorsed.dirs=/blah -Dnet.jxta.tls.principal=blah -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -cp [insert MASSIVE classpath here] /blah/blah.jar com.class.name.Here Param Param Param


I know in C it's an easy call to setproctitle(...); to set the process name that is displayed.  In fact some apps, like Sendmail, use this to provide a quick status display & activity for each child process -- very handy.  I realize that not all OSes have such functionality available, and those that do have different ways of accomplishing it, so this could be more difficult to do in a cross-platform way.

What would be nice is a simple API call to the JVM that would set it if the underlying OS has support, but I cannot find anything of the sort.  So the question is, how can I set the process title for my java app (at least on Linux, if not some other OSes)?
LVL 3
drcheapAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
I don't think you can without JNI. You can imagine that making it easy would make Java malware easier too

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drcheapAuthor Commented:
JNI, that's a little beyond my scope of Java knowledge right now -- I know what JNI is and have some idea of how to use it, but really that's all.  I guess I need to create some external library that does the title setting in Linux, and then just attempt to load & call it from the Java application (and ignore failures for other OSes)?

Any tips on how to actually go about doing that would be most helpful!

CEHJCommented:
>>and then just attempt to load & call it from the Java application

Yes. That's what you need JNI for
Mick BarryJava DeveloperCommented:
>  I guess I need to create some external library that does the title setting in Linux, and then just attempt to load & call it from the Java application

Almost. You create your external library that does the title setting. Then you create a JNI library that acts as a bridge between your java code and the native liubrary

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.