从终端和 iTerm 获取奇怪的行为“-bash:fork:资源暂时不可用”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13009632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:51:40  来源:igfitidea点击:

Getting strange behavior from terminal and iTerm "-bash: fork: Resource temporarily unavailable"

macosbash

提问by William Stocks

When I open iTerm, I'm getting this message:

当我打开 iTerm 时,我收到以下消息:

Last login: Mon Oct 22 12:20:25 on ttys002
-bash: fork: Resource temporarily unavailable
-bash-3.2$

上次登录: ttys002 上周一 10 月 22 日 12:20:25
-bash: fork: 资源暂时不可用
-bash-3.2$

and when I open Terminal, I'm getting:

当我打开终端时,我得到:

Last login: Mon Oct 22 12:25:47 on ttys002
-bash: fork: Resource temporarily unavailable
Williams-MacBook-Pro:~ william$

上次登录: ttys002 上的 Mon Oct 22 12:25:47
-bash: fork: 资源暂时不可用
Williams-MacBook-Pro:~ william$

and whenever I try to put in a command, like ls or cd i get this error message:

每当我尝试输入命令时,例如 ls 或 cd 我都会收到此错误消息:

-bash: fork: Resource temporarily unavailable

-bash: fork: 资源暂时不可用

So I basically can't do anything. I've tried googling the error message, but not getting anywhere. I'm on a Mac with Mountain Lion if that helps. Thanks.

所以我基本上什么都做不了。我试过谷歌搜索错误消息,但没有得到任何地方。如果有帮助,我正在使用带有 Mountain Lion 的 Mac。谢谢。

EDIT:

编辑:

I ran "ps"

我跑了“ps”

to get the process status and i got this as a response from terminal:

获取进程状态,我得到了这个作为终端的响应:

Williams-MacBook-Pro:~ william$ ps
PID TTY TIME CMD
203 ttys000 0:00.08 -bash
254 ttys001 0:00.03 bash /Users/william/.rvm/scripts/wrapper ruby-1.9.3-p2
553 ttys001 0:00.03 bash /Users/william/.rvm/scripts/wrapper ruby-1.9.3-p2
785 ttys001 0:00.03 bash /Users/william/.rvm/scripts/wrapper ruby-1.9.3-p2
814 ttys001 0:00.48 -bash
1019 ttys001 0:00.03 bash /Users/william/.rvm/scripts/wrapper ruby-1.9.3-p2

Williams-MacBook-Pro:~ william$ ps
PID TTY TIME CMD
203 ttys000 0:00.08 -bash
254 ttys001 0:00.03 bash /Users/william/.rvm/scripts/wrapper ruby​​-1.9.3-p2
5003.t003 bash /Users/william/.rvm/scripts/wrapper ruby​​-1.9.3-p2
785 ttys001 0:00.03 bash /Users/william/.rvm/scripts/wrapper ruby​​-1.9.3-p2
814 -ttys001 0:00
1019 ttys001 0:00.03 bash /Users/william/.rvm/scripts/wrapper ruby​​-1.9.3-p2

and the message

和消息

bash /Users/william/.rvm/scripts/wrapper ruby-1.9.3-p2

bash /Users/william/.rvm/scripts/wrapper ruby​​-1.9.3-p2

keeps listing a few hundred times in the terminal (couldn't post it all cause it probably wouldn't fit into this box and it just keeps going the same), so I'm guessing there's something sketchy going on with that file. Does anyone know how to fix this?

在终端中不断列出数百次(无法全部发布,因为它可能不适合这个盒子,而且它一直保持不变),所以我猜那个文件有一些粗略的事情。有谁知道如何解决这一问题?

回答by Daniel Kamil Kozar

bash- and all the other shells, too - use the forksystem call on Unix systems in order to actually create the process that you want to launch from the shell. In this case, bashtells you that the system call ended with Resource temporarily unavailable, which translates to the errnovalue of 11, which is equal to EAGAIN.

bash- 以及所有其他外壳程序 -fork在 Unix 系统上使用系统调用来实际创建要从外壳程序启动的进程。在这种情况下,bash告诉您系统调用以 结束Resource temporarily unavailable,它转换为errno11的值,它等于EAGAIN

The manual page for forksays that it may set errnoto EAGAINwhen :

对于手册页fork说,它可以设置errnoEAGAIN时:

  • It cannot allocate sufficient memory to copy the parent's page tables and allocate a task structure for the child.
  • It was not possible to create a new process because the caller's RLIMIT_NPROCresource limit was encountered. To exceed this limit, the process must have either the CAP_SYS_ADMINor the CAP_SYS_RESOURCEcapability.
  • 它无法分配足够的内存来复制父级的页表并为子级分配任务结构。
  • 由于RLIMIT_NPROC遇到调用者的资源限制,无法创建新进程。要超过此限制,进程必须具有CAP_SYS_ADMINCAP_SYS_RESOURCE能力。

In this case, I think that the first reason doesn't really sound realistic, unless you are actually out of memory, so I guess you just must've hit the limit for the number of running processes for your user.

在这种情况下,我认为第一个原因听起来不太现实,除非您确实内存不足,所以我猜您一定是达到了用户运行进程数的限制。

回答by jcasner

To resolve on Yosemite and newer versions of Mac OS, use https://superuser.com/a/838630. I was able to resolve by updating the plistfiles and rebooting - the ulimitcommands were unnecessary.

要解决 Yosemite 和更新版本的 Mac OS,请使用https://superuser.com/a/838630。我能够通过更新plist文件并重新启动来解决- 这些ulimit命令是不必要的。

回答by Warri

For iTerm, opening a new tab worked for me

对于 iTerm,打开一个新标签对我有用