开发者

How can I determine the command used to start the current jvm?

开发者 https://www.devze.com 2023-01-26 20:05 出处:网络
I plan to spawn a child to do some work. I want to spawn the child using the same command line as the parent process.

I plan to spawn a child to do some work. I want to spawn the child using the same command line as the parent process.

For example, if the parent was started like so:

#>/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 classpath from the System properties. And instead of using Run开发者_StackOverflowtime.exec I plan to use ProcessBuilder, which copies the environment of the parent to the child's environment. But basically I want to use the same java program and arguments as the parent gets. I haven't found this information in the System properties.


You can use JMX:

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


With JDK 6, there is command named jinfo which helps you to identify what arguments provided

You just need to your Process Id, and to know that, you can use jps command, it will show you all running jvm processes and ids.

So with below command, you can able to get all command line passed. With the same command you can change some property dynamacally(just see jinfo -h)

jinfo

0

精彩评论

暂无评论...
验证码 换一张
取 消