POSIX_SPAWN 与 Java?
ProcessBuilder.start 和 Runtime.exec 似乎在 *NIX 系统上使用 fork() ,这似乎为子进程分配与父进程相同数量的内存(参见例如 这个问题)。如果您想从使用大量内存的进程中启动一个几乎不需要内存的进程,这可能会很痛苦。
有没有什么方法可以使用 POSIX_SPAWN 启动进程——它不进行内存分配?我知道的唯一方法是使用 Tanuki,但事实证明这对我来说并不理想。
ProcessBuilder.start and Runtime.exec seem to use fork() on *NIX system, which seems to allocate the child process the same amount of memory as the parent process (see e.g.
this question ). This can be painful if you want to launch a process which needs almost no memory from a process that uses lots of memory.
Is there any way to launch processes using POSIX_SPAWN -- which doesn't do this memory allocation? The only way I know of is using Tanuki, but turns out to be not ideal for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 NuProcess 库。它在Linux上使用VFORK,不会先复制进程空间,从而消除了从具有大堆的java进程中fork进程时频繁出现的OOM错误。
Use the NuProcess library. It uses VFORK on Linux which does not copy the process space first, thereby eliminating the frequent OOM errors when forking processes from a java process with a large heap.
的开源项目
这是一个实现 posix_spawn https://github.com/axiak/java_posix_spawn
Here's an open source project which implements posix_spawn
https://github.com/axiak/java_posix_spawn
由于 Java 13+
ProcessBuilder.start
使用posix_spawn
。请参阅:https://bugs.openjdk.org/browse/JDK-8213192。Since Java 13+
ProcessBuilder.start
usesposix_spawn
. See: https://bugs.openjdk.org/browse/JDK-8213192.