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
.)