On Tue, 25 Oct 2005 15:08:15 -0400, JPerlmutter wrote:
> using this test script:
>
> ******************** code separator ********************
> #! /usr/bin/perl
> use strict;
>
> my $many = @ARGV[0];
> my $done=0;
>
> print "test: many is $many\n\n";
>
> while($done < $many){
> # exec "$0 0"; # kills this to create a new one
> # system "$0 0"; # creates new one with return to this one, not terminal?
> # `$0 0`; # creates new one and waits on return to this one?
> # fork; # creates binary progression (0->1; ... 10 -> 1024; ... 20
> ->1048576 ...)
>
> $done++;
> }
> print "hello world\n";
> __END__
> ******************** code separator ********************
>
> i found fork makes numbers that most can get some of fast, but even i cant
> really do past 20 with ease in my head (yes i know i'm a mathematical
> freak. try asking me things i know how to apply to reality in my sleep.
> based on a joke, my sister when we were younger, did once, sadly i spit
> out the answer practically as soon as the question is finished with an
> accuracy that.. well i got all the questions right that she asked....and
> after college, i'd only call myself mediocre (sp?) at math.) so i'm trying
> to look for something that will create one child with each pass. i dont
> mind them being background, just as long as a human that doesnt know
> better can look and know immediately they are running.
I think you don't understand how fork works. You were lucky you didn't
take down your system; what you created used to be a reliable way of doing
so. perldoc perlipc has... far more information that you really want,
unfortunately. pp.36-38 of Lincoln Stein's Network Programming with Perl
are excellent, if you happen to have a copy within reach.
Basically you need to do something like
unless (fork) {
exec '... command ... ';
}
To test for errors in forking (unlikely):
if (defined(my $pid = fork)) {
$pid or exec '... command ... ';
}
else {
die "Can't fork: $!\n";
}
But find a decent tutorial on fork or, just like the real thing, you could
poke yourself in the eye by accident.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs