ulimit -n
sets the soft limit by default; you can add the -H
option to view/set the hard limit.
For the most part, soft and hard limits behave like this:
- root's processes (actually, any process with
CAP_SYS_RESOURCE
) may raise or lower any limit on any process.
- any user's processes may lower any limit on other processes owned by that user.
- any user's processes may raise the soft limit up to the hard limit on processes owned by that user.
- If a process attempts to exceed its soft limit, the attempt will fail.
So, hard limits function as a cap on soft limits (except for root, who as normal can do anything).
There is an exception: A soft CPU limit sends a SIGXCPU
signal. A process may choose to ignore that, or spend time doing cleanup, etc. Once the hard CPU limit is crossed, the kernel sends SIGKILL
—which is not catchable, handleable, or ignorable. So in this case, the soft limit functions as a warning "you're out of CPU time—finish up and exit promptly, or else!" and the hard limit is the "or else."
Most are per-process, but a few (such as RLIMIT_NPROC
) are per user. The getrlimit(2) manual page specifies for each limit.
ulimit -n
? It doesn't affect processes already fired off, only the shell and future ones. Other than that, the process may be upping its soft limit to the hard limit. So you could useulimit -H -n
to stop it. – derobert Mar 08 '14 at 06:39