81

I tried installing Intel MPI Benchmark on my computer and I got this error:

fork: retry: Resource temporarily unavailable

Then I received this error again when I ran ls and top command.

What is causing this error?

Configuration of my machine:

Dell precision T7500
Scientific Linux release 6.2 (Carbon)
2

2 Answers 2

85

This is commonly caused by running out of file descriptors.

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

sysctl fs.file-nr

This returns counts of file descriptors:

<in_use> <unused_but_allocated> <maximum>

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

sudo su - <username>
ulimit -Hn

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

sudo lsof -u <username> 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.

fs.file-max = 204708
4
  • 17
    FYI, you can use "sysctl -p" to apply the current settings in /etc/sysctl.conf saving the reboot.
    – EmmEff
    Commented Feb 28, 2014 at 15:26
  • 2
    Also, if you have read only /etc, you can use 'sysctl -w fs.file-max=204708' at runtime. Commented Aug 24, 2015 at 10:34
  • you can also add it directly to kernel without reboot but not permanently 'echo 999999 > /proc/sys/fs/file-max'
    – mati kepa
    Commented Aug 24, 2018 at 8:35
  • sysctl fs.file-nr command is not working in Mac Commented Aug 5, 2022 at 4:14
52

Another possibility is too many threads. We just ran into this error message when running a test harness against an app that uses a thread pool. We used

watch -n 5 -d "ps -eL <java_pid> | wc -l"

to watch the ongoing count of Linux native threads running within the given Java process ID. After this hit about 1,000 (for us--YMMV), we started getting the error message you mention.

5
  • 2
    When I tested, ps -eL worked for showing all processes and ps -L <pid> worked for showing processes regarding the <pid>. ps -eL <pid> just shows all processes regardless of the <pid>. Commented Jul 1, 2016 at 9:51
  • 1
    @Willie Wheeler What did you do to overcome the thread limit? I have been searching and testing numerous solutions found online, to no avail, for DAYS. Nothing will allow more than 1k threads, except for a restart of systemd-logind, which lasts for about an hour before the errors start again! Commented Jul 27, 2016 at 4:00
  • Machines have finite resources. If you are hitting a limit, use fewer threads (e.g. controlled with thread pool) or else more machines.
    – user41871
    Commented Sep 21, 2016 at 15:41
  • I restarted my rails server
    – thedanotto
    Commented Nov 30, 2016 at 0:48
  • 2
    1000 threads isn't a lot though
    – frankster
    Commented Jun 6, 2017 at 10:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.