Using Runtime.exec to fork another instance of the current process
-
18-09-2019 - |
Question
I'm trying to use Runtime.exec to start a copy of the current process. I am not necessarily interested in a fork because I don't need to share state. Is there a way I can determine the command used to start the current process and just re-run this?
Solution 2
I ended up pulling the class path from System.getProperty("java.class.path") with that I was able to recreate the command line argument.
OTHER TIPS
If on linux maybe you could execute a "ps -eax" command and grep for your pid (not sure how to get the current vm pid) to get the full command that started your vm?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow