`
daly1987
  • 浏览: 7644 次
文章分类
社区版块
存档分类
最新评论

执行Runtime.exec异常: error=12,Cannot allocate memory .

阅读更多
转载一下:
Exception Trace:

In the Linux circumstance, when the program executes till this place:
Process p = Runtime.getRuntime().exec(cmdArr);
it throws an exception like this:
java.io.IOException: Cannot run program "/opt/X.sh": java.io.IOException: error=12, Cannot allocate memory

        at java.lang.ProcessBuilder.start(ProcessBuilder.java:474)

        at java.lang.Runtime.exec(Runtime.java:610)

        at java.lang.Runtime.exec(Runtime.java:448)

        at java.lang.Runtime.exec(Runtime.java:345)

        ...

Caused by: java.io.IOException: java.io.IOException: error=12, Cannot allocate memory

        at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)

        at java.lang.ProcessImpl.start(ProcessImpl.java:81)

        at java.lang.ProcessBuilder.start(ProcessBuilder.java:467)

        ... 4 more

These are the status and environment for it:

Top:
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

16405 root      19   0 6484m 5.1g  10m S  101 86.7   4:09.11 java

Free:
             total       used       free     shared    buffers     cached

Mem:       6108084    5616532     491552          0       2244     185100

-/+ buffers/cache:    5429188     678896

Swap:      2104472      12584    2091888


As shown before, the program has hold about 87% memory. When the memory usage is low, there is no exception throwed. It could be why java program fails to process “Runtime.exec()”.



The Official Explains:

Bug ID:
5049299

Votes
45

Synopsis
(process) Use posix_spawn, not fork, on S10 to avoid swap exhaustion

Category
java:classes_lang

Reported Against
5.0 , b06 , 1.4.2_04

Release Fixed
  
State
6-Fix Understood, request for enhancement

Priority:
2-High

Related Bugs
6381152 , 6605835 , 6728616 , 6745199 , 6845504 , 6850720 , 4343908 , 4391042

Submit Date
18-MAY-2004

Description
If you run a "small" program (e.g., a Perl script) from a "big" Java process on

a machine with "moderate" free swap space (but not as much as the big Java

process), then Runtime.exec() fails.




http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5049299




Cause Detail:

This issue dues to the operating mechanism of “Runtime.exec” in Java.
In Java program, “ProcessBuilder.start” and “Runtime.exec” use fork() on *NIX system, which allocates the child process the same amount of memory as the parent process. This will double the used memory for a short time. So when the Java main process has used over 50% memory, it will absolutely never launch a child process using “Runtime.exec” successful, even the process needs almost no memory.


Solutions:

There are three workable solutions:

1. The middleware of Tanuki may solve this problem. The question is, it is complicated and also expensive.

    See-  http://wrapper.tanukisoftware.com/doc/english/child-exec.html

2. Separate the process using “Runtime.exec” from the main process into a new java process. So when the “Runtime.exec” is called ,it will only double the memory of the new process, using almost no memory.

which means:

    a. When start/stop the main process, the “Runtime.exec” process should be started/stopped at the same time.

    b. Add an independent socket in the main process to communicate with the new process. The exec command will be delivered to the new process to execute.

This will surely increase the complexity and maintenance of the system.



3. Update JDK1.6 to JDK1.7

This bug is fixed in JDK1.7 ,using new invoking mechanism of external program.

(Pipes be tested in JDK snapshot release: build 1.7.0-b147,passed with no exceptions; it also reduced the memory usage for about 20%)

This will need no modification for current source code.





Quote:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5049299

http://hi.baidu.com/lewutian/blog/item/3a60a2fa553f6115a9d31172.html

http://www.cnblogs.com/happyy/archive/2010/11/28/1890111.html

http://wrapper.tanukisoftware.com/doc/english/child-exec.html

分享到:
评论

相关推荐

    编译时virtual memory exhausted Cannot allocate memory 内存增加.docx

    在执行编译程序时,如果虚拟机的内存不足,可能会出现“Virtual Memory Exhausted: Cannot Allocate Memory”的错误提示。这是因为编译程序需要占用大量的内存空间,而虚拟机的内存不足以满足编译程序的需求。 解决...

    Linphone编译错误及解决方法

    12. configure: error: Missing libv4l2. It is highly recommended to build with libv4l2 headers and library. Many camera will won't work or will crash your application if libv4l2 is not installed. 错误...

    forge-bootstrap-2.0.0.Alpha7.zip

    标题中的"forge-bootstrap-2.0.0.Alpha7.zip"是一个软件开发框架的版本压缩包,Forge Bootstrap 提供了一个快速启动新项目的环境,通常包含了基本的项目结构、配置和依赖管理,使得开发者能够更便捷地搭建开发环境。...

    C#读取JPEG图片的Exif信息

    [Serializable] public class EXIF { #region -- Class level members -- // Class level members. private Image _picture; #endregion #region -- Constructors -- // Constructors. ...

    无法解析的外部符号”private: char * __cdecl cv::String::allocate(unsigned __int64)” (?allocate@String@cv@@AEAA

    1&gt;save-image-D435.obj : error LNK2001: 无法解析的外部符号 “private: char * __cdecl cv::String::allocate(unsigned __int64)” (?allocate@String@cv@@AEAAPEAD_K@Z) 1&gt;save-image-D435.obj : error LNK2001: ...

    解决出现CUDA error-out of memory的问题.pdf

    然而,在训练深度学习模型时,我们经常遇到“CUDA error: out of memory”这样的错误,这表明GPU的显存不足以运行当前的任务。本文将详细介绍这个问题的原因、影响以及解决方法。 ### 问题原因 1. **模型复杂度过...

    高中英语词根词缀表.doc

    7. al-:加强意义(例:allocate 分配) 8. am-:加强意义(例:almost 几乎) 9. an-:无,不(例:anarchistic 无政府的) 10. anti-:反对,相反,防止(例:antibiotics 抗生素) 词缀 词缀是英语单词中的一...

    大气校正.pdf

    3.ACC error:avrd: IDL error:Unable to allocate memory:to make array Not enough space 解决方法是在高级设置里面(Advanced Settings),tile size:设置稍微大一些,如100~200m。 4.ACC error:avrd:No ...

    新东方新四级词汇-正序版.pdf

    - allocate(vt. 分配):指将资源、资金等指定用于特定目的。 - allowance(n. 津贴):给予个人的钱作为补贴或额外的收入。 - ally(n. 同盟):指与其他国家、团体或个人结成的伙伴关系。 - alongside(prep. ...

    详解解决Python memory error的问题(四种解决方案)

    昨天在用用Pycharm读取一个200+M的CSV的过程中,竟然出现了Memory Error!简直让我怀疑自己买了个假电脑,毕竟是8G内存i7处理器,一度怀疑自己装了假的内存条。。。。下面说一下几个解题步骤。。。。一般就是用下面...

    计算机英语单词.pdf

    12. accessory: 附件,辅助设备。 13. achievevt.: 实现,完成(动词形式)。 14. ACK: 确认信号,即Acknowledge(确认)的缩写。 15. acoustic: 声音的,声学的。 16. acquire: 获得,获取。 17. acquisition: 获取...

    ENVI大气校正常见问题

    3.ACC error:avrd: IDL error:Unable to allocate memory:to make array Not enough space。 解决方法是在高级设置里面(Advanced Settings),tile size:设置大一些,如 100~200m。 4.ACC error:avrd:No ...

    系统问题详细解决方法攻略

    1. 定期维护:执行磁盘清理、磁盘碎片整理等操作,保持系统的良好运行状态。 2. 数据备份:定期备份重要文件,以防系统崩溃时数据丢失。 3. 安全防护:安装可靠的防病毒软件,并保持更新,防止病毒和恶意软件入侵。 ...

    delphi 读取硬盘序号

    Result := 'Failed to allocate output buffer.'; end; finally if hDevice &lt;&gt; INVALID_HANDLE_VALUE then CloseHandle(hDevice); FreeMem(lpInBuffer); FreeMem(lpDrvStatus); FreeMem(lpOutBuffer); end;...

    JLink_Windows_V648.zip

    DLL: When using J-Trace PRO with IAR EWARM a "failed to allocate x bytes of memory" error could occur. Fixed. DLL: Windows: Renesas RX: When using FINE interface and disabling ongoining debug mode on ...

    程序员常用英语词汇.pdf

    23. allocate: 分配、配置,为对象或数据指定内存空间。 24. allocator: 分配器,内存分配机制或对象。 25. anglebracket: 尖括号,在编程中用于泛型声明。 26. annotation: 注解、评注,为代码添加元数据的语法结构...

    centos8安装kafka_2.11-2.4.1.docx

    error='Cannot allocate memory' (errno=12) There is insufficient memory for the Java Runtime Environment to continue. Native memory allocation (mmap) failed to map 1073741824 bytes for committing ...

    软件开发语言

    12. 错误与异常(Errors and Exceptions): - accurate(adj. 精确的):没有偏差的,完全准确的。 - ambiguity(n. 含糊):有多种可能解释的模糊状态。 这份词汇表详细地罗列了这些与软件开发紧密相关的英语...

    cdecl回调处理.rar

    1. 库与应用程序交互:库开发者可能需要提供一种方式,让应用程序能够在特定时刻执行自定义操作,回调函数可以实现这一点。 2. 事件驱动编程:当某个事件发生时,回调函数会被调用,执行相应的处理逻辑。 3. 异步...

Global site tag (gtag.js) - Google Analytics