如何确定用于启动当前jvm的命令?

时间:2022-12-03 20:45:49

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 Runtime.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.

我知道我可以从System属性中找到类路径。而不是使用Runtime.exec我计划使用ProcessBuilder,它将父项的环境复制到子环境。但基本上我想使用与父获取相同的java程序和参数。我没有在系统属性中找到此信息。

2 个解决方案

#1


1  

You can use JMX:

您可以使用JMX:

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

#2


-1  

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

使用JDK 6,有一个名为jinfo的命令可以帮助您识别提供的参数

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.

您只需要您的Process Id,并且要知道,您可以使用jps命令,它将显示所有正在运行的jvm进程和ID。

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 -h)

jinfo

#1


1  

You can use JMX:

您可以使用JMX:

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

#2


-1  

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

使用JDK 6,有一个名为jinfo的命令可以帮助您识别提供的参数

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.

您只需要您的Process Id,并且要知道,您可以使用jps命令,它将显示所有正在运行的jvm进程和ID。

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 -h)

jinfo