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. [poj] 1236 networks of schools

    原题 这是一道强连通分量板子题. 显然subtask1 是要输出入度为0的点的个数 而subtask2,我们考虑一下最优一定是把一个出度为零的点连到入度为零的点上,这样我们要输出的就是max(出度为零 ...

  2. 回文后缀(suffix)

    回文后缀(suffix) 题目描述 给定字符集大小 SS ,问有多少个长度为 NN 的字符串不存在长度 >1>1 的回文后缀. 答案对 MM 取模. 输入格式 第一行两个正整数 n, kn ...

  3. SJCL:斯坦福大学JS加密库

    斯坦福大学Javascript加密库简称SJCL,是一个由斯坦福大学计算机安全实验室创立的项目,旨在创建一个安全.快速.短小精悍.易使用.跨浏览器的JavaScript加密库.(斯坦福大学下载地址:h ...

  4. gdb 脚本

    不满足于一条一条执行命令,我们可以将命令写进脚本里面,连续执行, 1: gdb启动会在当前目录寻找.gdbinit文件,并读取里面的命令列表 2: 我们可以启动gdb 时,加-x cmd.gdb 来指 ...

  5. 新建module---获取带宽信息

    借鉴自http://blog.csdn.net/xjtuse2014/article/details/53968726 1.MoniterBandwidth模块: package net.floodl ...

  6. Vim文字编辑

    首先说明发现的vim编辑器的一个特点:vim编辑只有按[ENTER]键或命令模式下[o]才会换行,否则虽然在vim编辑器里显示的内容换行了,但事实上没有换行.如果你发现自己测试的效果和下面描述的不符, ...

  7. Python学习杂记_12_函数(三)

    内置函数 Python有很多内置函数,以下这些是常用且必须要掌握的: 强制类型转换: bool() # 把一个对象转换成布尔类型 int() # 整形 float() # 小数 str() # 字符 ...

  8. AC日记——[HNOI2012]永无乡 bzoj 2733

    2733 思路: 启发式合并splay(n*log^2n): 来,上代码: #include <cstdio> #include <cstring> #include < ...

  9. aliyun

    阿里云启动不了网站 1  将网站的目录属性-安全中加入IUSER_计算机名字的访问权限     和  加入NER SERVICE的访问权限 2 IIS打开网站属性--目录--执行权限改为顺脚本 3  ...

  10. js-限制参与活动的范围(微信H5活动)

    近期接到大连某个项目,一个H5的活动,其中有一个需求就是:这个活动的参与者仅限大连地区的用户 所以参考了微信API 得出的操作结果为: wx.ready(function() { wx.getLoca ...