doowah2004 has asked for the wisdom of the Perl Monks concerning the following question:
This should create 99 lines in the output file and it does. I then change the code to:#!/usr/bin/perl -w use strict; use Time::HiRes qw(usleep ualarm gettimeofday tv_interval); open (FILE, ">testfork.txt"); my $runs = 33; my $start = [gettimeofday]; while ($runs) { my $pid = fork; # Parent if ($pid) { $runs--; } # Child if ($pid == 0) { my $pid = fork; if ($pid == 0) { my $pid = fork; if ($pid == 0) { print FILE "$runs\n"; exit; } print FILE "$runs\n"; exit; } print FILE "$runs\n"; exit; } } my $elapse = tv_interval ($start); close (FILE); print "Elapsed time = $elapse\n"; exit;
#!/usr/bin/perl -w use strict; use Time::HiRes qw(usleep ualarm gettimeofday tv_interval); open (FILE, ">testfork.txt"); my $runs = 99; my $start = [gettimeofday]; while ($runs) { my $pid = fork; # Parent if ($pid) { $runs--; } # Child if ($pid == 0) { # my $pid = fork; # if ($pid == 0) { # my $pid = fork; # if ($pid == 0) { # print FILE "$runs\n"; # exit; # } # print FILE "$runs\n"; # exit; # } print FILE "$runs\n"; exit; } } my $elapse = tv_interval ($start); close (FILE); print "Elapsed time = $elapse\n"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Uninitialized value in numeric eq (==) after 65 iteration of a loop using fork?!?
by ccn (Vicar) on Sep 13, 2004 at 14:24 UTC | |
|
Re: Uninitialized value in numeric eq (==) after 65 iteration of a loop using fork?!?
by zejames (Hermit) on Sep 13, 2004 at 14:30 UTC | |
by doowah2004 (Monk) on Sep 13, 2004 at 14:45 UTC | |
by zejames (Hermit) on Sep 13, 2004 at 15:03 UTC | |
|
Re: Uninitialized value in numeric eq (==) after 65 iteration of a loop using fork?!?
by BrowserUk (Patriarch) on Sep 13, 2004 at 20:40 UTC | |
|
Re: Uninitialized value in numeric eq (==) after 65 iteration of a loop using fork?!?
by TheEnigma (Pilgrim) on Sep 13, 2004 at 16:25 UTC |