分配给通过 Java 调用的命令行程序的内存

Memory Allocated to Command Line Program Invoked through Java


假设我使用以下代码段

通过 java 调用命令行程序
 p = Runtime.getRuntime().exec(command);
 p.waitFor();

在这种情况下,exec调用的程序command会分配多少内存?它与分配给 jvm 的内存有什么关系吗? 如果是这样,我该如何克服这个限制?

更新
根据对这个问题的回答,How to solve "java.io.IOException: error=12, Cannot allocate memory" calling Runtime#exec()?

Runtime.getRuntime().exec allocates the process with the same amount of memory as the main. If you had you heap set to 1GB and try to exec then it will allocate another 1GB for that process to run.

那么有什么方法可以让我使用 java 调用的进程有更多内存吗?

如果我 运行 通过这样的命令提示符命令会怎样?

rt.exec("cmd.exe /c command");

这样的话,谁来决定内存限制呢?命令提示符或 Java?

javadoc for Runtime.exec 声明该命令将在 单独的进程 中启动。因此,命令本身将 运行 在其自己的进程中使用自己的内存,并且不会使用任何 JVM 内存。

当然,该方法也是 returns 一个 Process 对象,它本身会使用一些 JVM 内存,但这只是一些变量来跟踪进程已启动,因此除非您并行启动数万个进程,否则这应该不是问题。