Process Id in Unix

How can i get process id of the java program being executed in the unix environment programatically .
[109 byte] By [javatrend] at [2007-9-30 20:14:28]
# 1
AFAIK there is no pure Java way. Once I posted a JNI implementation on this forum., but not not find it any longer. If you put up with the PID of a starter script, you can do this:java -Dpid="$$" Caveat: threads under Linux show as processes.
BIJ001 at 2007-7-7 0:59:47 > top of Java-index,Administration Tools,Sun Connection...
# 2
http://forum.java.sun.com/thread.jsp?forum=4&thread=367608
BIJ001 at 2007-7-7 0:59:47 > top of Java-index,Administration Tools,Sun Connection...
# 3

Another suggestion was to exec an program which outputs its parent's PID. Something like this:

#include <unistd.h>

#include <stdio.h>

int main() {

printf("%d\n",getppid());

}

This works only if exec goes directly, that is, if there is no intermediate process.

BIJ001 at 2007-7-7 0:59:47 > top of Java-index,Administration Tools,Sun Connection...
# 4
> Another suggestion was to exec an program which outputs its parent's PID. This doesn't work so good on Windows, where there's no concept of a parent PID.
shankar.unni at 2007-7-7 0:59:47 > top of Java-index,Administration Tools,Sun Connection...
# 5
The question was, however, about "Process Id in Unix".
BIJ001 at 2007-7-7 0:59:47 > top of Java-index,Administration Tools,Sun Connection...