代码改变世界

-bash: fork: retry: Resource temporarily unavailable

2016-01-01 03:32  三犬风  阅读(1001)  评论(0编辑  收藏  举报

For me, I got the same error message but had a different solution.
Cron failed with : (CRON) ERROR (setreuid failed): Resource temporarily unavailable
Bash logins failed as described in the main topic (no disk access was allowed, but built in bash functions could be used like pwd or echo).

The fix was to edit /etc/security/limits.conf
My process was "apache" so I added 
apache soft nproc 2000

If you want it for all users, change apache to *

 

 


This is commonly caused by running out of file descriptors. 

There are different file descriptor limits.

There is the systems total file descriptor limit, what do you get from the command:

CODE: SELECT ALL
sysctl fs.file-nr


From this command you will get 3 numbers. First is the number of used file descriptor the second is the number of allocated but not used file descriptor and the last is the system max file descriptor. If either of the first two numbers are new otr at the third you need to increase the number of file descriptors for the system of find out what is consuming them. 

If the total of the used system file descriptors is not near the max it may be a user limit. 

To find out what a users file descriptor limit is run the commands:

CODE: SELECT ALL
sudo su - UID
ulimit -Hn


Replace UID with the user ID is the user you want to check, or if you are already logged in as that user just run the ulimit command. 

To find out how many file descripters are in use by a user run the command:

CODE: SELECT ALL
sudo lsof -u UID 2>/dev/null | wc -l



So now if you are having a system file descriptor limit issue you will need to edit your /etc/sysctl.conf file and add, or modify it it already exists, a line with fs.file-max and set it to a value large enough to deal with the number of file descriptors you need and reboot. 

The line would look somehting like:

CODE: SELECT ALL
fs.file-max = 204708



If it is a individual users file descriptor limit then you will have to update the users limits in the /etc/security/limits.conf file with an entry like:

CODE: SELECT ALL
UID soft nofile 4096
UID hard nofile 10240


Once again you will have to replace UID with the user ID of the account with the issue.