in reply to Re: How I'm sure syswrite has finished?
in thread How I'm sure syswrite has finished?

[ This was meant as a reply to Re: How I'm sure syswrite has finished? ]

if the parent is doing something after the for loop to cause the ssh processes to terminate.

I think it's simpler than that. When the parent exits, doesn't that kill the children? Calling wait_all_children is still the solution as that would make sure the children are done.

Replies are listed 'Best First'.
Re^2: How I'm sure syswrite has finished?
by casiano (Pilgrim) on Mar 14, 2009 at 22:18 UTC
    Many thanks ikegami,

    I tried wait_all_children (see answer below) but without success.

    Somehow the $pm->finish (I also tried a plain exit) with the same result aborts the whole writing?.

    I guess that somehow the call to syswrite produces a decoupled process in the remote machine than is in charge of fulfilling the writing (since it is a huge message). When the exit of the forked local child occurs the remote process is aborted?

      I think your issue is that the open of ssh on the local end is also a fork. I'm guessing that maybe close isn't waiting for the child to finish when using open2 the way it does for open. perlipc says open does but doesn't mention this regarding open2. I would wait for the ssh processes to finish before calling $pm->finish. See the waitpid function as well as perlipc.