|
Java™ by example!
|
|
|
How do I get the process ID on Windows?
You will have to use JNI for this. Using the following code, I'll create a DLL that provides the method getPid which will return the current process ID.
Pid.java:
Compile and run javah on it to create the pid.h header file:
It generates the C header file Pid.h:
The C code that allows to get the current process ID:
I used cygwin to develop a Windows DLL from this in the following way:
This DLL now allows you to get the process ID of your current Java app. Here's an example:
For those who don't have cygwin installed or want to start using it right away, here's the library:
Pid.dll
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|