Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Help with Fork bomb

by aitap (Deacon)
on Aug 30, 2012 at 15:53 UTC ( #990789=note: print w/ replies, xml ) Need Help??


in reply to Help with Fork bomb

$pid = fork; if ($pid == 0){ # Is a child $iterations++; sleep 1; } ... } } if ($pid == 0){ # Is a child exit; }
I think, the problem might be there: every child continues the loop after sleep 1 and creates more and more grandchildren. Placing exit after sleep fixed the issue for me: before after.

By the way, separate shell with ulimit -u 300 was very useful for testing this code.

Sorry if my advice was wrong.


Comment on Re: Help with Fork bomb
Select or Download Code
Re^2: Help with Fork bomb
by Anonymous Monk on Aug 30, 2012 at 20:11 UTC
    I think I've seen instances when exit in the child kills the parent. Is that possible? How does one defend against it?
          I think I've seen instances when exit in the child kills the parent

      Parricide? I suppose, but if you set up proper handling of SIGCHLD in your code and have a plan of what to do you should be OK.

      # ---- yadayadayada # # Handler for SIGCHLD $SIG{CHLD}=sub { # do something here } ;

      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

        I'm using Blue_cowdawg's code. It does this:

        $SIG{CHLD}=\&catchChildDeath; # Deal with the death of a child. A sad event to be sure. sub catchChildDeath{ printf "Death of child noted.\n"; $children--; $children = ( $children < 0 ? 0 : $children); unless ($spawnEnabled){ $spawnEnabled = ( $children < $min_child ? 1 : 0 ); } printf "There are %d children running\n",$children; }

        My sub that the child runs exits at its end:

        sub my_child_work{ my $x = shift; print "child x $x "; sleep 1; exit; }
      In addition to the previous comment, by default, perl ignores SIGCHLD, so dead children remain as zombies and die only when parent dies. You can avoid it by handling SIGCHLD as specified above.
      Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990789]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-09-22 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (189 votes), past polls