我想了解这里发生了什么.
linvx$( ulimit -u 123; /bin/echo nst ) nst linvx$( ulimit -u 122; /bin/echo nst ) -bash: fork: Resource temporarily unavailable Terminated linvx$( ulimit -u 123; /bin/echo one; /bin/echo two; /bin/echo three ) one two three linvx$( ulimit -u 123; /bin/echo one & /bin/echo two & /bin/echo three ) -bash: fork: Resource temporarily unavailable Terminated one
我推测前两个进程是由Bash本身使用的,剩下的ulimit控制着我允许的并发进程数.文档对此不太清楚.我错过了什么吗?
更重要的是,对于现实世界的部署,我怎么知道什么样的ulimit是现实的?它是一个长期运行的守护进程,它根据需要生成工作线程,并在负载减少时重新获取它们.我已经把服务器旋转了几次.最重要的限制可能是内存,我现在每个进程限制为200M,但是我想弄清楚如何对子进程实施限制(该程序允许我配置最大值,但是如何我知道这部分代码中没有错误吗?)
附录:在一个较新的系统上,我获得了更高的数字和稍微不同的行为.
xubuntu12.04$( ulimit -u 206; /bin/echo nst ) nst xubuntu12.04$( ulimit -u 205; /bin/echo nst ) bash: fork: retry: No child processes bash: fork: retry: No child processes bash: fork: retry: No child processes bash: fork: retry: No child processes bash: fork: Resource temporarily unavailable Terminated xubuntu12.04$bash --version GNU bash,version 4.2.24(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2011 Free Software Foundation,Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY,to the extent permitted by law.
我相信旧系统有Bash v3.
在破折号中,我得到了不同的行为,虽然仍然不是我期望的行为(并且该选项被称为-p而不是-u):
xubuntu12.04$dash $( ulimit -p 1; /bin/echo nst ) nst $( ulimit -p 2; /bin/echo nst & /bin/echo too & ) dash: 0: Cannot fork $( ulimit -p 208; /bin/echo nst & /bin/echo too & ) dash: 0: Cannot fork nst $( ulimit -p 209; /bin/echo nst & /bin/echo too & ) nst too