I'm running 200 processes, but a ulimit -u of 400 seems to cause some problem:

$ ps -A | wc -l
$ ulimit -u 400
zsh: fork failed: resource temporarily unavailable

I'm confused. Why is the limit being hit?

edit: Initially ulimit -u gives

$ ulimit -u
  • That's unusual; ulimit is a built-in command, so will not cause a fork. Does this happen under zsh -f? That is, is there something in your shell configuration that forksalot? – thrig Sep 2 '16 at 18:42
  • So you get that error right after changing ulimit? Does it do that for any (higher) limit? – Julie Pelletier Sep 2 '16 at 18:43
  • Are you running java or other multi-threaded code? – Stephen Harris Sep 2 '16 at 18:43
  • @thrig The thing that is forking is a command that is part of my shell prompt. – Owen Sep 2 '16 at 18:47
  • 1
    Note that production systems should not normally use ulimit for control as it may cause very undesired side-effects. – Julie Pelletier Sep 2 '16 at 18:51

On Linux threads count towards the ulimit -u count, but they don't show up normally with ps -A. You need to add the L flag.

eg on my machine:

% ps -A | wc -l 
% ps -AL | wc -l

We can see there's 31 more processes running; these are threads, normally hidden from view.

With java and other highly threaded applications it can be easy to run more threads/processes than you think. Your ulimit -u value needs to take this into account.

This can unexpectedly hit people running a lot of java applications on RedHat systems where it comes, by default, with a ulimit setting:

% cat /etc/security/limits.d/20-nproc.conf 
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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