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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.