-bash: fork: 无法分配内存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43652021/
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-18 16:04:59  来源:igfitidea点击:

-bash: fork: Cannot allocate memory

linuxbashmemoryubuntu-16.04

提问by Aman Jain

When I run any command in bash shell, it returns:

当我在 bash shell 中运行任何命令时,它返回:

$ free -m
-bash: fork: Cannot allocate memory

Then I tried debugging for memory leaks with the pscommand. It returns:

然后我尝试使用该ps命令调试内存泄漏。它返回:

$ ps --sort -rss -eo rss,pid,command | head
RSS   PID COMMAND
518116 1310 /usr/bin/influxd -pidfile /var/run/influxdb/influxd.pid -config /etc/influxdb/influxdb.conf
281700 1912 /opt/td-agent/embedded/bin/ruby /usr/sbin/td-agent --log /var/log/td-agent/td-agent.log --daemon /var/run/td-agent/td-agent.pid
68260 23896 /home/alphauser/Envs/vogo-alpha/bin/python ./manage.py runserver 0.0.0.0:8008
43720 20201 python ./manage.py runserver 0.0.0.0:8008
36928  2223 rsyslogd
27432  1909 /opt/td-agent/embedded/bin/ruby /usr/sbin/td-agent --log /var/log/td-agent/td-agent.log --daemon /var/run/td-agent/td-agent.pid
25296 15009 /usr/bin/telegraf -pidfile /var/run/telegraf/telegraf.pid -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d
24428 32529 /usr/sbin/grafana-server --pidfile=/var/run/grafana-server.pid --config=/etc/grafana/grafana.ini cfg:default.paths.data=/var/lib/grafana cfg:default.paths.logs=/var/log/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins
20792  2314 /var/lib/waagent/Microsoft.OSTCExtensions.LinuxDiagnostic-2.3.9025/bin/mdsd -A -C -c /var/lib/waagent/Microsoft.OSTCExtensions.LinuxDiagnostic-2.3.9025/./xmlCfg.xml -p 29131 -R -r lad_mdsd -e /var/log/azure/Microsoft.OSTCExtensions.LinuxDiagnostic/2.3.9025/mdsd.err -w /var/log/azure/Microsoft.OSTCExtensions.LinuxDiagnostic/2.3.9025/mdsd.warn -o /var/log/azure/Microsoft.OSTCExtensions.LinuxDiagnostic/2.3.9025/mdsd.info

How to debug? What is the core problem?

如何调试?核心问题是什么?

回答by Japneet Singh Chawla

I also faced this issue with my Ubuntu 14.04 desktop.

我的 Ubuntu 14.04 桌面也遇到了这个问题。

 free -m

Even these basic command showed Can't allocate memory error. On investigating, found that system is using all the memory for Caching and is not freeing up memory. This is called Cache Ballooning and solved this by clearing the cache.

即使这些基本命令也显示无法分配内存错误。在调查中,发现系统正在将所有内存用于缓存并且没有释放内存。这称为缓存膨胀,通过清除缓存解决了这个问题。

回答by Cody

You might first want to check your system memory usage to see if there's enough free memory left.

您可能首先要检查系统内存使用情况,看看是否有足够的可用内存。

If not, which is my case, please check your ulimit by typing ulimit -ato see if you've reached the limit of max open files (mostly caused by some certain processes that occupies a lot of file descriptors). In this case adjusting the ulimit will solve your problem.

如果不是,这是我的情况,请通过键入ulimit -a来检查您的 ulimit以查看您是否已达到最大打开文件的限制(主要是由某些占用大量文件描述符的某些进程引起的)。在这种情况下,调整 ulimit 将解决您的问题。

回答by sina rahmanian

I had the same problem. In my Case, after knowing about the detail of memory with "proc/meminfo", I found the PIDs that they used a lot of CPU and memory with "TOP".After that, I checked how long they have run with "ps -o etime= -p "PID"". Then I kill the PIDs with "kill -9 PID".

我有同样的问题。在我的案例中,在通过“ proc/meminfo”了解内存的详细信息后,我通过“ TOP”找到了他们使用大量CPU和内存的PID 。之后,我检查了他们使用“ ps -”运行了多长时间- o etime= -p "PID"". 然后我用“ kill -9 PID杀死PID

回答by Jin Mengfei

In my case, OS was running out of PID instead of memory, the error message was the same though.

就我而言,操作系统耗尽了 PID 而不是内存,但错误消息是相同的。

The default value of max PID number is 32768, to view the value, run

max PID number 的默认值为 32768,要查看该值,请运行

cat  /proc/sys/kernel/pid_max

To change the max pid number, run

要更改最大 pid 数,请运行

echo 100000 > /proc/sys/kernel/pid_max

In my scenario, the root cause was that one java prcocess spawned 18k+ threads( in linux kernel, thread is essentially a process), to find out the thread count of each process, run

在我的场景中,根本原因是一个 java 进程产生了 18k+ 个线程(在 linux 内核中,线程本质上是一个进程),要找出每个进程的线程数,运行

ps -eo nlwp,pid,args --sort nlwp