runtime.getruntime.exec 的内存问题 [英] memory issue with runtime.getruntime.exec

查看:73
本文介绍了runtime.getruntime.exec 的内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议 java 的 Runtime.getRuntime().exec 函数的替代方法吗?我将一个 unix 命令作为参数传递给这个函数,但它会导致内存问题.Runtime.getRuntime().exec fork 一个新进程,其内存量与 java 进程占用的内存量完全相同,导致内存需求翻倍,这正是我不想要的.

can somebody suggest an alternative to Runtime.getRuntime().exec function of java. I am passing a unix command as an argument to this function but it causes a memory issue. Runtime.getRuntime().exec forks a new process with exactly the same amount of memory as being occupied by java process, causing the memory requirement to double which is exactly what I don't want.

推荐答案

这是可选的,取决于操作系统.在 Linux 上,内存是惰性"分配的,直到真正需要为止.您查找的关键字是内存过量使用",这里可能会出现这种情况.

This is optional and depends on the operating system. On Linux, the memory is "lazyly" allocated, until really needed. The keywords you look for are "memory overcommit", which is a situation that can arise here.

阅读"fork 如何处理内存",或这个 了解更多.您可能已禁用过量使用行为,因此您的分叉进程始终会立即分配所有内存.

Read "How does fork handle memory", or this to learn more. You probably have disabled the overcommit behaviour, so your forked process always allocates all memory immediately.

这篇关于runtime.getruntime.exec 的内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆