Subject: | Proc::Simple is returning (and hijacking) my own process |
A weird behavior of this module is crashing my script. When I do something like $myproc = Proc::Simple->new(), sometimes $myproc is still my current process instead of a brand new child process. To verify it, I wrote a simple script called teste.pl. The shell(with also uname -a and perl -v output) and the script is descripted below. Note there is a warning message about line 240 of Simple.pm.
Show quoted text
>>>>>>>>>>>>>>>>>> teste.pl >>>>>>>>>>>>>>>>>>
#!/usr/bin/perl -w
use Proc::Simple;
my($tries);
$tries = 100;
$parentpid = $$;
print "Starting my tries. Parent pid = $parentpid\n";
while ($tries) {
my ($process);
$process = Proc::Simple->new();
$process->start( sub { if ( $parentpid eq $$ ){
print "Hey! Something goes wrong!\n";
exit(1);
} else {
print "Hi! My PID is $$\n";
sleep 35;
exit(0);
}
} );
$tries--;
}
print "I finished my tries! Good luck!\n";
Show quoted text>>>>>>>>>>>>>>>>>>>>>>>> output >>>>>>>>>>>>>>>
$ uname -a
SunOS XXXXXXX 5.8 Generic_108528-18 sun4u sparc SUNW,Ultra-60
$ perl -v
This is perl, v5.8.1 built for sun4-solaris-thread-multi
Copyright 1987-2003, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
$ perl teste.pl
Starting my tries. Parent pid = 9865
Hi! My PID is 9866
Hi! My PID is 9867
Hi! My PID is 9868
Hi! My PID is 9869
Hi! My PID is 9870
Hi! My PID is 9871
Hi! My PID is 9872
Hi! My PID is 9873
Hi! My PID is 9880
Hi! My PID is 9881
Hi! My PID is 9882
Hi! My PID is 9883
Hi! My PID is 9884
Hi! My PID is 9885
Hi! My PID is 9886
Hi! My PID is 9887
Hi! My PID is 9888
Hi! My PID is 9889
Hi! My PID is 9890
Hi! My PID is 9891
Hi! My PID is 9892
Hi! My PID is 9893
Hi! My PID is 9894
Hi! My PID is 9895
Hi! My PID is 9896
Hi! My PID is 9897
Hi! My PID is 9898
Hi! My PID is 9899
Hi! My PID is 9900
Hi! My PID is 9902
Hi! My PID is 9903
Hi! My PID is 9904
Hi! My PID is 9901
Hi! My PID is 9905
Hi! My PID is 9906
Hi! My PID is 9907
Hi! My PID is 9908
Hi! My PID is 9910
Hi! My PID is 9909
Hi! My PID is 9911
Hi! My PID is 9912
Hi! My PID is 9913
Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/site_perl/5.8.0/Proc/Simple.pm line 240.
Hey! Something goes wrong!
#!/usr/bin/perl -w
use Proc::Simple;
my($tries);
$tries = 100;
$parentpid = $$;
print "Starting my tries. Parent pid = $parentpid\n";
while ($tries) {
my ($process);
$process = Proc::Simple->new();
$process->start( sub { if ( $parentpid eq $$ ){
print "Hey! Something goes wrong!\n";
exit(1);
} else {
print "Hi! My PID is $$\n";
sleep 35;
exit(0);
}
} );
$tries--;
}
print "I finished my tries! Good luck!\n";