I have the code below. As you can see, in the child processes, I'd like to
have data pushed onto an array (@test). However, nothing ever gets pushed.
I've tried push, I've tried setting $test[$x]=time; I've tried using
scalars, I just can't get any data out of the fork()ed processes.
What's going on? How can I get info from them?
Thanks,
Richard Morey
#!/usr/bin/perl
use LWP::Simple;
@URLs=(" " "" "
@test=();
# start 5 processes
for ($x=0;$x<=$#URLs;$x++)
{
&start_a_child;
}
# wait for the processed to finish
while (!$endloop)
{
$pid = wait; # wait on a child process to exit
print "Process number $pid just finished.\n";
$endloop=1 if ($pid==-1);
}
print "Program ended successfully.";
sub do_something
{
print "I am process number $$ and I am about to"
. " do something.\n";
$info=(get $URLs[$x]);
print "And now process number $$ ($URLs[$x]) is done.\n";
}
sub start_a_child
{
$pid = fork;
die "Can't fork ($!)\n" unless defined $pid;
if (not $pid)
{
&do_something;
push(@test, time);
exit;
}
}
have data pushed onto an array (@test). However, nothing ever gets pushed.
I've tried push, I've tried setting $test[$x]=time; I've tried using
scalars, I just can't get any data out of the fork()ed processes.
What's going on? How can I get info from them?
Thanks,
Richard Morey
#!/usr/bin/perl
use LWP::Simple;
@URLs=(" " "" "
@test=();
# start 5 processes
for ($x=0;$x<=$#URLs;$x++)
{
&start_a_child;
}
# wait for the processed to finish
while (!$endloop)
{
$pid = wait; # wait on a child process to exit
print "Process number $pid just finished.\n";
$endloop=1 if ($pid==-1);
}
print "Program ended successfully.";
sub do_something
{
print "I am process number $$ and I am about to"
. " do something.\n";
$info=(get $URLs[$x]);
print "And now process number $$ ($URLs[$x]) is done.\n";
}
sub start_a_child
{
$pid = fork;
die "Can't fork ($!)\n" unless defined $pid;
if (not $pid)
{
&do_something;
push(@test, time);
exit;
}
}