in reply to Re: Windows filehandles and fork
in thread Windows filehandles and fork

Commenting out the select line makes it likely that the parent will run it's print before the child does the open(STDOUT) which is causing the problem. You are then in a nasty state because then whenever the child get's arround to opening STDOUT, the parent's print statements will be spontaneously redirected. This is bad behavior.

It looks to me like something is broken in the fork emulation in ActivePerl.

Replies are listed 'Best First'.
Re: Re: Re: Windows filehandles and fork
by Koosemose (Pilgrim) on Apr 09, 2004 at 06:53 UTC

    I'd most likely agree with you, but to be honest I don't know to much about fork and how it's supposed to work. I am still in the process of studying the appropriate chapter in the Camel. But I do recall it mentioning that forks in perl were implemented with threads of some sort ( ithreads I think ) but was bent to more resemble a Unix Fork.

    I do hope I made it clear in my first post that I didn't really know what was going on. I am however, curious why my first example seems to run as expected, or is this also a situation of the open happening after the other process has already printed it's message.

    I'm also not entirely clear as to what select is doing. I can't seem to find any mention of that particular form in perlfunc. And neither of the two mentions in perlipc seem to say what they're doing.

    Update: Ack, Just realized I should probably look in the camel, and managed to dig up what select is doing, apparently it's just putting a minor delay in one of the processes, I assume the purpose in the initial verion was to make certain that one process' print happened after the other's open, so it would seem that both my examples seemed to have the desired effect only due to (in one case) the random chance of one of the print's happening before the open. And in the other case because the open itself was delayed, making certain that the other process got it's print out beforehand. bleh...

    Just Another Perl Alchemist
      Yes, The select's were for sub-second pauses. Sorry. I've probably been programming in perl too long, I don't even notice I'm using tricks like that anymore. I should have put sleep()'s in there instead to make it clear.

      So you see my issue, changing the timing changes where the output goes which makes it unpredictable and dangerous. Perl isn't usually unpredictable or dangerous. Something is wrong here.

      The guys who do POE seem to have gotten something like this working, although their code is all in modules so first I'd have to figure out how to get POE to do what I want, then I'd have to trace the code to see what it's doing all without knowing if it actually does work right.