jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Identifying Java Processes on UNIX boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Identifying Java Processes on UNIX boxes" Watch "Identifying Java Processes on UNIX boxes" New topic

Identifying Java Processes on UNIX boxes

Graham Kelly

Joined: Nov 11, 2004
Posts: 3
Hi, not sure this is the correct forum, but the UNIX forum seems to be more about UNIX than Java.

Does anyone know of a way to identify the classes running on a java VM within UNIX? 'ps' only shows the 'java' process. 'ps -f' shows a certain amount fo the actual command line used to run the JVM, but in most cases, the first arg is the classpath, so you don't get to see the actual class or jar that is being run (i.e. the class containing main).

Is there a way to query the JVM to get the main class? Possibly a 'jps'
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245

shows complete command lines. (suse linux)

You only need to redirect ps to another program or file.
Graham Kelly

Joined: Nov 11, 2004
Posts: 3
Sorry. I should have mentioned the UNIX flavour. I'm using HP UX 11. The ps command only returns a shortened command line, as in:

corbausr 6107 1 0 Nov 9 ? 3:12 /opt/java1.3/bin/../bin/PA_RISC2.0/native_threads/java -clas

As you can see, it's barely started the argument to specify the CP, never mind the actual class to run.

I found on the web examples saying 'ps -exf', but the 'x' argument reports an error in my flavour of UNIX. I 'man'ed ps and it talks about the -o argument to giva the actual columns I'm interested in, but that's only applicable to 'XPG4' and, again, doesn't work with my flavour.

I was thinking there may be some java way to do this rather than a UNIX way.

I found a utility called 'grash' that allows you to explore the JVM in a UNIX like manner, but that's experimental and I can't use it in production code (anyway, it needs to be imported and used by the class, not an outside process, though I could have it initiated by a hook that the outside process connects to).
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You sure that output isn't to do with your terminal line settings? Seems odd ps is truncating the response. Try it with a --cols switch.

There isn't a Java way to do this that I can think of - processes are always the domain of the OS.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Henry Wong

Joined: Sep 28, 2004
Posts: 18874

In all of the flavors of unix that I played with, "ps" always truncated the lines, if the output is going to the terminal. If you pipe it to a program, such as "grep", it will not truncate.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
GeeCON Prague 2014
subject: Identifying Java Processes on UNIX boxes