Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How I'm sure syswrite has finished?

by perl5ever (Pilgrim)
on Mar 14, 2009 at 18:47 UTC ( [id://750640]=note: print w/replies, xml ) Need Help??


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

I agree with ChemBox that the parent should wait for the children to finish. Have a look at the wait_all_children method.

Your problem is likely happening after the for loop. Note that the parent process will get done with the for loop much earlier than the child processes. One way the messages sent by the children may get truncated is if the parent is doing something after the for loop to cause the ssh processes to terminate.

Replies are listed 'Best First'.
Re: How I'm sure syswrite has finished?
by ikegami (Patriarch) on Mar 14, 2009 at 19:54 UTC

    [ 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.

      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.
Re^2: How I'm sure syswrite has finished?
by casiano (Pilgrim) on Mar 14, 2009 at 22:06 UTC
    I tried this:
    153 foreach (@str_handles) { 154 my $pid = $pm->start and next; 155 156 $b = syswrite $_->{handle}, 157 join(" ", 158 $_->{chunksize}, 159 $_->{A_cols}, 160 @A_lines[$_->{start}.. $_->{end}], 161 @B_lines, 162 "\cN" 163 ); 164 # Wait until the writing has finished 165 #sleep(1); 166 $pm->finish; 167 } 168 $pm->wait_all_children;
    But the behavior is the same.

    Only the sleep seems to work.

    My guess is that

    $pm->finish;
    produces a "fake termination": the local process ends while the remote is still writing?

      I think you need to show us more of your program - especially the part wher eyou create the ssh connections.

      Also, the output of strace or truss would help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://750640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-23 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found