develooper Front page | perl.perl5.porters | Postings from November 2011

Re: [perl #6847] strange behaviour when forking lots of times

Thread Previous | Thread Next
From:
Eric Brine
Date:
November 23, 2011 11:12
Subject:
Re: [perl #6847] strange behaviour when forking lots of times
Message ID:
CALJW-qGbY82bSRuS9JYs2xe2V1wF-ehf0p0ww3z4vG5hitqG3A@mail.gmail.com
On Wed, Nov 23, 2011 at 5:46 AM, Aaron Crane <perl@aaroncrane.co.uk> wrote:

> James E Keenan via RT <perlbug-followup@perl.org> wrote:
> > On Sat Apr 21 01:36:46 2001, dpc29@cam.ac.uk wrote:
> >> $ perl -we 'fork || print for split //, "a" x 10'
> >>
> >> when I run that on my computer, I get strange output.  Instead of
> >> printing "a" 2**10 times, the output contains random "1"'s, like this:
> >>
> >> aa1aaaaa1aaa1aaaaa1aaa1aaaa1aaa1aaaaaa1aaaaa1aa1aaaaaa1a
> >>
> >> It also affects different computers differently; the "x 10" needs to
> >> be replaced by a higher value to get the same effect sometimes (but
> >> not too high, or you'll fork-bomb your computer).
> >
> > I have recently confirmed that this behavior still exists.  It taught me
> > the meaning of 'fork-bomb'. :-(
>
> A hypothesis: this is being run with an RLIMIT_NPROC in place (aka
> `ulimit -u`).  In particular, if RLIMIT_NPROC is at or near 2**n, then
> some of the forks are likely to fail with EAGAIN when the literal 10
> in the code is replaced with an integer >= n; whereas choosing a lower
> number will make things work.  That certainly matches the behaviour
> I'm seeing.  This slightly modified code should emit "a" in every
> child process, "1" if the fork failed with EAGAIN, or "0" if the fork
> failed for some other reason:
>

I'm not clear on why fork failing would cause $_ to be changed from 'a' to
1.

Your code is actually significantly different as the ones output by your
code originate from a print the OP did not have.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About