in reply to basic fork question
To answer your questions directly:
1. You want to check for $pid before forking
# mostly from the camel book if ($pid = fork) { .... #parent } elsif (defined $pid) { ... #child exit; }
But, if your forking creates thousands of processes at once you will likely overload your system and get locked out. As long as you have an exit in the child, you should be okay as far as this is concerned.
2. To make the parent wait until all the child are finished you use a sigalert. I am not an expert on the syntax here, maybe others can add to that, but basically you can set an alert to have the parent wait until the child sends a signal to continue.
3. I am not sure I understand your third question. Store what? The array? The parent already has the array. Can you clarify?
UPDATE: Marcello is right, of course. I didn't mean my code to be usable but just a cursory example. I hope I didn't mislead anyone.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: basic fork question
by Marcello (Hermit) on Jan 19, 2002 at 21:11 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |