trippledubs has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
Can you explain why this script hangs? Thanks for looking.#!/usr/bin/env perl use strict; use warnings; my $trials = 1000; sub bdayRuns { my $space = shift // 2**16; my $avg; TRIAL: for (1..$trials) { my %keys; for my $chance (1..$space) { my $r = int(rand($space)); if (++$keys{$r} > 1) { $avg+= $chance; next TRIAL; } } } $avg = $avg / $trials; return "Average collision out of $space: $avg : Runs: $trials\n"; } pipe(my $rh, my $wh); for (1..4) { my $pid = fork; if (!$pid) { #child print $wh " $$ - " . bdayRuns(365); exit; } } print "$_" while (<$rh>); 1 until wait == -1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forking script hangs
by oiskuu (Hermit) on Jun 10, 2015 at 20:44 UTC | |
by afoken (Chancellor) on Jun 10, 2015 at 21:46 UTC | |
by trippledubs (Deacon) on Jun 11, 2015 at 04:33 UTC | |
|
Re: forking script hangs
by MidLifeXis (Monsignor) on Jun 10, 2015 at 20:39 UTC |