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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.