in reply to A Quick fork theory question

Okay... I have that figured out, thank you all for your help... Now what I am noticing, however, is that each child process is running in sequence, not concurrently. Is there a way in perl to make the processes run parrellel? I.e. force some sort of concurrency / automatic waiting / context switch(other than polling the cpu and calling a sleep() every few milliseconds)?
Thanks in advance, EBitch

Replies are listed 'Best First'.
(tye)Re: A Quick fork theory question
by tye (Sage) on Jun 15, 2001 at 23:22 UTC

    Um, fork is what makes the children run in parallel. If that isn't happening here, then your children probably aren't doing much (since you aren't using wait or waitpid, which can be used to make the parent wait children). Doing some trick to make the children to appear more like they are running in parallel will just slow things down.

    If you just want to see that they are running in parallel, then insert a sleep 5 in your child code.

            - tye (but my friends call me "Tye")
Re: Re: A Quick fork theory question
by Malkavian (Friar) on Jun 15, 2001 at 20:23 UTC
    One possible solution is to use something like Proc::Simple to handle all your forks as nice simple objects.
    In your parent body, install a sig handler that traps, say SIGUSR1.
    On a child death, the child 'kills' the parent with SIGUSR1, making it wake up from a lengthy sleep, or other work, and take care of the signal in whatever way you want.
    I'd use SIGUSR1, as I may be doing other things that invoke pipes, and that keeps invoking the SIGCHLD handler, if I install that. Which gets messy.
    At least with SIGUSR1, you can be pretty sure it's what you want sending the signal.
    In Proc::Simple, you simply iterate over an array of process objects to see which ones have died and how.

    Hope this helps a little,

    Malk