Disadvantage of fork

linux环境下, JBoss中调用curl下载文件,  发现curl占用的内存和JBoss一样多。

Historical Background and Problem Description

Traditionally, Unix has had only one way to create a new process: using a fork() system call, often followed by an exec() system call. The fork() call makes a copy of the entire parent process' address space, and exec() turns that copy into a new process.

(Note: In the Solaris OS, the term swap space is used to describe a combination of physical memory and disk swap space configured for the system. However, with other Unix systems this term may mean swap space on disk, also known as backing store. To avoid any confusion, I'll use the term Virtual Memory (VM) to mean physical memory plus disk swap space.)

Generally, the fork/exec method has worked quite well. However, it has disadvantages in some cases, such as running out of memory without a good reason and poor fork performance.

Out of Memory: For a large-memory process, the fork() system call can fail due to an inadequate amount of VM, because fork() requires twice the amount of the parent memory. This can happen even when fork() is immediately followed by an exec() call that would release most of that extra memory. When this happens, the application will usually terminate.

For example, suppose a 64-bit application is consuming 6 gigabytes (Gbytes) of VM at the moment, and it needs to create a subprocess to run the ls(1) command. The parent process issues a fork() call that will succeed only if there is another 6 Gbytes of VM available at the moment. If the system doesn't have that much VM available (which is a frequent situation), fork() will fail with ENOMEM. Obviously, the ls(1) command doesn't need anywhere near 6 Gbytes of memory to run, but fork() doesn't know that.

Not only applications, but also Sun's own tools can suffer from the same problem. For example, the following Sun RFE (request for enhancement) has been filed for dbx: "4748951 dbx shell should use posix_spawn() for non-builtin commands rather than fork(2)".

RFE 4748951 came about when a customer's utility invoked dbx to read a huge core file using a script that also needed to run a cut(1) command from within dbx. They got a cannot fork - try again error message causing dbx to abort. An investigation revealed that dbx used fork/exec to execute that tiny cut(1) command and ran out of VM during the fork() call.

The Solaris Java Virtual Machine (JVM) is also suffering from the same problem currently, as described in this Sun RFE: "5049299 Use posix_spawn, not fork, on S10 to avoid swap exhaustion".

From what Linux kernel/libc version is Java Runtime.exec() safe with regards to memory?

linux fork的缺点的更多相关文章

  1. 【转载】linux fork死循环炸弹及其预防

    转自linux fork死循环炸弹及其预防 在Linux系统下执行这段代码 :(){ :|:& }:: 就会引起死机,一旦执行起来后,唯一的方法就是重启系统.实际上这段代码是一段无限递归代码, ...

  2. linux fork进程请谨慎多个进程/线程共享一个 socket连接,会出现多个进程响应串联的情况。

    昨天组内同学在使用php父子进程模式的时候遇到了一个比较诡异的问题 简单说来就是:因为fork,父子进程共享了一个redis连接.然后父子进程在发送了各自的redis请求分别获取到了对方的响应体. 复 ...

  3. Python垃圾回收和Linux Fork

    前言 在口袋助理看到了其他部门的同事针对Python2内存占用做的一点优化工作,自己比较感兴趣,遂记录下. Linux fork简介 fork是Linux提供的创建子进程的系统调用.为了优化创建进程速 ...

  4. Linux fork()、exec() Hook Risk、Design-Principle In Multi-Threadeed Program

    目录 . Linux exec指令执行监控Hook方案 . 在"Multi-Threadeed Program"环境中调用fork存在的风险 . Fork When Multi-T ...

  5. 最诡异的Linux fork进程问题(我们平时都在写)

    从来没有遇到过... 运行环境:在Linux自带的文本编辑器中输入C程序,在shell中编译运行,下面直接看代码和运行结果. 第一个代码:#include<stdio.h> #includ ...

  6. linux fork函数与vfork函数,exit,_exit区别

    man vfork: NAME vfork - create a child process and block parent SYNOPSIS #include <sys/types.h> ...

  7. Linux fork exec等

    http://www.cnblogs.com/leoo2sk/archive/2009/12/11/talk-about-fork-in-linux.html http://www.cnblogs.c ...

  8. linux fork()

    一. linux下C语言可以用fork()建立子进程.fork函数返回两个值,对于子进程,返回0; 父进程,返回子进程ID. 所以用if(fork()==0)      {子进程执行的代码段:}els ...

  9. Linux fork创建子进程

    1.  pid_t fork(void); 功能:创建父子进程 参数:无 返回值:成功:在父进程中:返回值为子进程的PID 在子进程中:返回值为0 失败:-1 注意: 1)fork函数是用来创建进程的 ...

随机推荐

  1. Manacher算法学习 【马拉车】

    好久没写算法学习博客了 比较懒,一直在刷水题 今天学一个用于回文串计算问题manacher算法[马拉车] 回文串 回文串:指的是以字符串中心为轴,两边字符关于该轴对称的字符串 ——例如abaaba 最 ...

  2. jquery defered的progress方法实现进度条

    效果如图: 实现代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  3. ionic2.x 手动搭建开发环境教程分享(nodejs,jdk,ant,androidsdk)

    1.ionic简介 为什么选用ionic: 1.     彻底开源且免费 2.     性能优异 3.     基于红的发紫的AngularJs 4.     漂亮的UI 5.     强大的命令行( ...

  4. webpack最佳入门实践系列(3)

    6.使用图片 6.1.尝试在css中引入图片 在src目录下新建css文件夹,并且在css文件夹下创建app.css文件,在src目录下新建images文件夹,放入一张图片,在app.css中引入这张 ...

  5. SHTSC2017酱油记~~~

    一转眼,SHTSC2017就结束了呢... [前记] noip2016的时候,day2由于各种奇奇怪怪的原因,于是策略上犯错误,然后直接滚粗... 作为一个SHTSC2016年就莫名其妙当上B队队长的 ...

  6. LayoutInflater学习总结

    ----参考,转载,借用来源:http://blog.csdn.net/guolin_blog/article/details/12921889 Activity类中onCreate方法中,setCo ...

  7. 限制MYSQL从服务器为只读状态

    修改全局变量的方法有两种,第一种是修改配置文件,第二种是SQL语句设置全局变量的值.(可以参考:http://www.cnblogs.com/qlqwjy/p/8046592.html) 0.简介: ...

  8. 【原创】Linux环境下的图形系统和AMD R600显卡编程(10)——R600显卡的3D引擎编程

    3D图形处理流水线需要流经多个硬件单元才能得到最后的渲染结果,流水线上的所有的硬件单元必须被正确编程,才能得到正确的结果. 总体上看,从图形处理流水线的源头开始,需要准备好vertex和index,在 ...

  9. hdu 1558(计算几何+并查集)

    Segment set Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. Matlab,C++存取二进制

    1,Matlab存储二进制 load Wall.dat %读取数据,数组名为Wall fid=fopen('Wall','wb'); %打开一个文件,二进制写入 fwrite(fid,Wall','f ...