>
> HI. First time poster... :)
>
For some reason your message was marked as SPAM, and not by me, as I
don't have spam filters enabled....
> I am trying to write a script that spawns a number of children processes.
> The number of children processes is determined at run time based on a
> configuration file. I am having trouble finding a way to create these
> children processes. They have to be independant of the parent and all run
> simultaniously untill they have completed their job or the parent send
them
> a terminate signal.
>
> The fork command appears to only create a single child process. I may need
> potentially 20 or more.
>
> Backticks and the system() command will not work because the parent
process
> waits for the child to complete before continuing.
>
> I'm hoping I can somehow embed a fork command inside a while loop like so:
>
> $children = 10;
> while ($children > 0)
> {
> # fork a child process here somehow...
> $children--;
> }
>
> Thanks,
> Brian
>
>
This is a somewhat frequently asked message on this list, search the
archives on fork and I bet you will find more resources. I would start with:
perldoc perlipc
perldoc -f fork
perldoc -f waitpid
Those should give you a good base. In general you are correct about
using a while loop with fork code inside the loop. Be sure not to fork
bomb your machine, and you will need to decide things such as whether it
will run as a daemon and whether you just want X number of forks to run
and then exit or whether you want X number to always be alive, etc.
Depending on what you are really up to you might want to check the Perl
Cookbook and/or Network Programming with Perl, both are excellent
resources and contain chapters on this sort of stuff.
As is generally the case when talking about IPC I must mention POE
depending on your complexity and desire/ability to learn,
http://poe.perl.org
HTH,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>