Monday, April 26, 2004 02:01 PM
I had to do a temporary hack once for some debugging. I think you have to step outside the Java worldview to get such non-portable info.
Maybe we didn't do it the best way but it was just a quick hack for debugging.... First we had to check if it was running under Windows or Unix. Then depending on that, we had to issue the appropriate command in a Runtime.exec() e.g. "ps" or whatever, Windows Resource Kit equivalent, I forget. Then we had to parse the output for something we could recognize (e.g. RTFM ps, or the Windows Resource Kit equivalent's doc).
If you're stuck on Solaris instead of Linux/MacOS/BSD etc., I would explicitly go with "/usr/ucb/ps" (the one that takes "aux" args) instead of just "ps", by the way... the SysV "ps" (the one that takes "elf" args) is not as useful, in my opinion, since it doesn't give you the "argv" command name by which the process was actually invoked. With the real "ps" (Linux etc.) AKA "/usr/ucb/ps" (on Solaris), especially as "ps auxwww" to get full details in as wide an output format as possible, you do get this argv for each process, which is easier to parse/search for.