AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 449363
Accepted
tripleee
tripleee
Asked: 2012-11-17 02:52:42 +0800 CST2012-11-17 02:52:42 +0800 CST 2012-11-17 02:52:42 +0800 CST

了解 ulimit -u

  • 772

我想了解这里发生了什么。

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

我推测前 122 个进程由 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。

在dash中,我得到了不同的行为,尽管仍然不是我期望的行为(并且调用了选项-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
linux
  • 2 2 个回答
  • 15317 Views

2 个回答

  • Voted
  1. Best Answer
    Charles Duffy
    2013-04-21T06:33:48+08:002013-04-21T06:33:48+08:00

    不仅子 shell 中的子进程会受到限制,而且系统上的所有内容都在您的 uid 下。

    因此,如果您在系统的任何地方有 200 个进程以您自己的身份运行,则一个进程ulimit -u 205只能分叉,直到总计数达到 205 —— 即五次(如果没有任何退出)。

    • 6
  2. Danie
    2013-01-23T04:14:36+08:002013-01-23T04:14:36+08:00

    这就是 ulimit 的工作方式。

    如果您希望允许一个用户运行 4 个进程,

    您将有 1+4 (一个用于用户当前正在使用的 bash 进程)

    从我的测试来看,

    创建了一个用户测试,

    ran ulimit -u 1
    

    无法运行任何命令,因为 bash 已经是一个正在运行的进程,

    ran ulimit -u 2
    

    只能运行一个进程,例如,

    ps aux -> returned value but ps aux | grep test -> did not return as it's using 2 processes
    

    最后,不建议在您的根帐户上使用 ulimit,ulimit 主要用于大型多用户环境。

    我希望这有帮助!

    干杯,

    ===============

     -a     All current limits are reported
     -b     The maximum socket buffer size
     -c     The maximum size of core files created
     -d     The maximum size of a process’s data segment
     -e     The maximum scheduling priority ("nice")
     -f     The maximum size of files written by the shell and its children
     -i     The maximum number of pending signals
     -l     The maximum size that may be locked into memory
     -m     The maximum resident set size (many systems do not honor this limit)
     -n     The maximum number of open file descriptors (most systems do not allow  this
                         value to be set)
     -p     The pipe size in 512-byte blocks (this may not be set)
     -q     The maximum number of bytes in POSIX message queues
     -r     The maximum real-time scheduling priority
     -s     The maximum stack size
     -t     The maximum amount of cpu time in seconds
     -u     The maximum number of processes available to a single user
     -v     The maximum amount of virtual memory available to the shell
     -x     The maximum number of file locks
     -T     The maximum number of threads
    
    • 2

相关问题

  • Linux 主机到主机迁移

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 在 RHEL4 上修改 CUPS 中的现有打印机设置

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve