I ran into a problem of :

fork: Resource temporarily unavailable

I know that nproc is the problem Some suggested to increase the soft limit of nproc while other suggested the hard limit.

Which should I increase? Isn't the soft limit is there just to warn the user and the hard limit is the one that really limits eventually?


It's actually other way around.

The soft limit's value(s) is actually implemented i.e. in use, you can increase the limit upto the relevant hard limit's value(s) (assuming you are not super user or do not have CAP_SYS_RESOURCE capability).

  • So the hard limit is just a limit of the soft limit for regular users? – Liron Cohen Nov 9 '16 at 11:53
  • @LironCohen You can think that way for understanding. – heemayl Nov 9 '16 at 11:53
  • So what happens if only the hard limit specified? – Liron Cohen Nov 9 '16 at 12:06

Think of the hard and the soft limits as mandatory and discretionary limits, resp. The hard limit is imposed by the system (through suitable configuration, e.g. limits.conf(5)) and can be increased only by the superuser (i.e. root), while the user can gauge soft limits at his discretion within the range of the according hard limits.

From the getrlimits(2) manual page:

The soft limit is the value that the kernel enforces for the corresponding resource. The hard limit acts as a ceiling for the soft limit: an unprivileged process may set only its soft limit to a value in the range from 0 up to the hard limit, and (irreversibly) lower its hard limit.

Thus, if you hit a resource limit, then check whether you can increase the according soft limit; if not, then the hard limit needs to be increased.

Response to Comment

There is no such thing as only the hard limit. Limits are set by setrlimit(2), which refers to struct rlimit. This in turn has members for soft and hard limit (rlim_cur and rlim_max, resp.). If a soft limit is not explicitly defined, then it defaults to some value; most likely the according hard limit, but this is up to the process that sets the limits. (setrlimits(2) rejects rlim_cur exceeding rlim_max, so RLIM_INFINITY is typically not a valid default for rlim_cur.)

  • What happens if only the hard limit specified? – Liron Cohen Nov 9 '16 at 14:46
  • 1
    @LironCohen see my edit – countermode Nov 9 '16 at 15:16

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.