java-native-access / jna

Java Native Access
Other
8.55k stars 1.68k forks source link

Add support for cross-platform process tagging to identify stray processes #820

Open jjYBdx4IL opened 7 years ago

jjYBdx4IL commented 7 years ago

Such a thing would be really helpful, ie. when doing integration tests with servers that get started during build processes. Java has serious issues regarding process management for years now. I can't even reliably kill stray processes during my builds in a cross-platform way. Currently, I put special environment variables into my programs' environments. That way I can always identify them via /proc, tho programs have to run under UNIX-like systems for that to work, including cygwin (bash). Programs started under Windows via cmd.exe do not register with cygwin's /proc, ie. their environment variables need to be read via Windows dlls.

jjYBdx4IL commented 7 years ago

Here is an open-source (GPLv3 with exceptions) http://processhacker.sourceforge.net/ windows process management tool that should provide all the required answers. Maybe its author is willing to move core functions into a library and release it under GPL with classpath exception? If not, its sources should still be an extremely helpful pointer.

Apart from that, I'm already using some sort of process snapshots in my own sources: https://github.com/jjYBdx4IL/github-utils/blob/master/src/main/java/com/github/jjYBdx4IL/utils/windows/ProcessList.java tho I'm not sure how easy it is from there.

matthiasblaesing commented 7 years ago

If some one wants to have a look at this, this might help:

https://www.codeproject.com/KB/threads/ReadProcEnv.aspx