Anyone familiar with BSD::Resource and how setrlimit(RLIMIT_NPROC) works in Linux?
I'm confused by how RLIMIT_NPROC works. What is it limiting, exactly? It seems that when I do setrlimit(RLIMIT_NPROC, $soft, $hard) and $soft<=$hard, then I cannot do any double fork (like system("echo 123")) at all, no matter whether $soft is 1 or 100.
perl -MBSD::Resource -le'setrlimit(RLIMIT_NPROC,20,50); system qq(echo 1);' # hangs, fork fails with EAGAIN perl -MBSD::Resource -le'setrlimit(RLIMIT_NPROC,20,20); system qq(echo 1);' # also hangs
But when $soft >= ($hard+1) there doesn't seem to be any limit that I'm hitting, I can do multiple forks even when $soft=2 and $hard=1.
perl -MBSD::Resource -le'setrlimit(RLIMIT_NPROC,20,10); system qq(echo 1);' # succeeds perl -MBSD::Resource -le'setrlimit(RLIMIT_NPROC,2,1); system qq(echo 1);' # succeeds perl -MBSD::Resource -le'setrlimit(RLIMIT_NPROC,2,1); for(1..10){if(fork==0){print"child $_";sleep 1;exit}}; waitpid(-1,0)' # succeeds, prints "child 1".."child 10"
I'm using 2.4 kernel on Debian Sarge/i386.
In reply to BSD::Resource and RLIMIT_NPROC on Linux by dgaramond2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |