转:http://blog.csdn.net/chifengxin/article/details/6573134
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
相关推荐
jtoml.zip,用于tomltoml的java解析器用于java的解析器
[Serializable] public class EXIF { #region -- Class level members -- // Class level members. private Image _picture; #endregion #region -- Constructors -- // Constructors. ...
1>save-image-D435.obj : error LNK2001: 无法解析的外部符号 “private: char * __cdecl cv::String::allocate(unsigned __int64)” (?allocate@String@cv@@AEAAPEAD_K@Z) 1>save-image-D435.obj : error LNK2001: ...
跑模型时出现RuntimeError: CUDA out of memory.错误 查阅了许多相关内容,原因是:GPU显存内存不够 简单总结一下解决方法: 将batch_size改小。 取torch变量标量值时使用item()属性。 可以在测试阶段添加如下代码:...
编译时virtual memory exhausted Cannot allocate memory 内存增加.docx
列举了一些Linphone编译错误及解决办法,给有需要的人,只是我遇到的错误,可能不全面。
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 ...
error=’Cannot allocate memory’ (errno=12) 原因:内存空间不足 解决办法:由于 elasticsearhc 默认分配空间为2g,可以通过修改配置文件 /config/jvm.options,降低分配的内存空间 vim /conf/jvm.opti
OS error code 12: Cannot allocate memory 操作系统错误代码12:无法分配内存 OS error code 13: Permission denied 操作系统错误代码13:权限被拒绝 OS error code 14: Bad address 操作系统错误代码14:错误的...
用来查找算法 ... // allocate memory: buffer = new char [length]; // read data as a block: is.read (buffer,length); is.close(); cout.write (buffer,length); delete[] buffer; return 0;
1. Allocate 16MB space in memory as the storage for your file system. The space is divided as blocks with block size 1KB Assume block address length is 32-bit; Design the information contained in i...
用来查找算法 ... // allocate memory: buffer = new char [length]; // read data as a block: is.read (buffer,length); is.close(); cout.write (buffer,length); delete[] buffer; return 0;
NULL 博文链接:https://czmmiao.iteye.com/blog/2277675
Android在启动模拟器AVD时,出现下面的异常:“Failed to allocate memory: 8”,怎么办? 此错误是我们在允许AVD时,选择了默认的AVD插件所致。 解决方法:减少分配的内存大小。修改AVD的配置文件,将选项“hw.ram...
12="NAND invalid timeout value" 13="NAND invalid parameter" 14="NAND erase block error" 15="NAND get map error" 16="NAND configurate SSD Info. error" 17="NAND ...
metheads# => [:allocate, :new, :superclass, :freeze, :===, :==, :<=>, :<, :<=, :>, :>=, :to_s, :inspect, :included_modules, :include?, :name, :ancestors, :instance_methods, :p
V1.13 (2009年12月14日修复列表) .# 对在线升级功能进行了改进,提高兼容性和稳定性; .# 对程序进行优化,后台运行效率明显加快; .# 修改地方服务子分类不可修改Bug; .# 修复修改网址信息后自动跳转会出现...
Ubuntu16.04编译Android源码7.0和4.4及踩坑 一.虚拟机环境配置 1.1Ubuntu怎样修改软件源地址 1.2共享文件夹 1.3虚拟机配置 ...二....2.1将源文件拷贝到linux环境下后解压并编译 ...fatal: fork: Cannot allocate memory
This means that Windows will allocate 4096 bytes for any file or portion of a file that is from 1 to 4096 bytes in length. ... Another example would be if I have a file that is 2000 bytes in size. ...
docker 报错 1. 查看原因 ... error=‘Cannot allocate memory’ (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mma