I need PID(Process ID)of process on UNIX machine. Can anyone tell how to obtain in my program at runtime? I tried working with Runtime.exec() but it did not work out since exec method does not allow this.
but as per the doc even you referred " Runtime.exec() is not a command line - One final pitfall to cover with Runtime.exec() is mistakenly assuming that exec() accepts any String that your command line (or shell) accepts. Runtime.exec() is much more limited and not cross-platform. This pitfall is caused by users attempting to use the exec() method to accept a single String as a command line would. The confusion may be due to the fact that command is the parameter name for the exec() method. Thus, the programmer incorrectly associates the parameter command with anything that he or she can type on a command line, instead of associating it with a single program and its arguments. In listing 4.6 below, a user tries to execute a command and redirect its output in one call to exec():" .
Have you actually tried it? "ps" is an executable in Unix, not a command built into the shell, so you should have no problems. The pipe ("|") may not work, in which case you have to parse the full output of the ps command, but that's not much harder than parsing a single line.