How to determine the command used to run the current jvm?

I plan to have a baby in order to do some work. I want to give birth to a child using the same command line as the parent process.

For example, if the parent was started as follows:

#>/usr/bin/java ParentProgram 

then I would call

 Runtime.exec("/usr/bin/java ChildProgram"); 

Example 2:

 #>/usr/bin/jdb -cp ./:/home/name/tool/library.jar -Xmx4G ParentProgram 

then I would call

 Runtime.exec("/usr/bin/jdb -cp ./:/home/name/tool/library.jar -Xmx4G ChildProgram"); 

I know that I can find the class path from the System properties. And instead of using Runtime.exec, I plan to use ProcessBuilder, which copies the parent environment to the child environment. But basically I want to use the same java program and arguments as the parent. I did not find this information in the system properties.

+4
source share
2 answers

You can use JMX:

 List<String> args = ManagementFactory.getRuntimeMXBean().getInputArguments(); 
+1
source

With JDK 6, there is a command called jinfo to help you determine which arguments are provided

You just need to specify your process identifier and know that you can use the jps command, it will show you all running jvm processes and identifiers.

So, with the command below you can get the whole command line. Using the same command, you can change some property dynamically (just see Jinfo -h)

jinfo

-1
source

All Articles