Hi. What I have is a script that I first started on when I was completely new to perl. It has gotten fairly large, several subroutines and whatnot, centered around the Net::AIM module. At the time, I don't think that I understood the concept of fork(), but it sounded like what I needed to easily have more than one of my scripts running at once. Now it seems like I have a problem...
I have a seperate script to use fork to spawn several instances of the main script, and replace them when they exit. It looks a little like this:
my $counter;
for ($counter = 1; $counter <= 3; $counter++) {
$pid = fork();
if ($pid) {
$child{$pid} = $counter;
} else {
exec "perl main.pl arg1 arg2";
exit $counter;
}
}
while ($counter) {
$doneproc = wait();
$doneval = $? >> 8;
$pid = fork();
if ($pid) {
$child{$pid} = $counter;
$counter++;
} else {
exec "perl main.pl arg1 arg2";
exit $counter;
}
}
Now, this works great. But after doing some reading this morning, I'm wondering if there's a way to get around using the exec line. If possible, I would like to avoid the overhead cost of having several perl.exe instances active. It seems like the way I'm doing things is contradictory to the purpose of fork.
Am I wrong? .. or what should I do? The way Net::AIM works, it looks like it's beyond my capabilities to rewrite the script in a way that it can be properly forked... I'm confused, and my brain hurts. Help!
Thanks,
Berto.