in reply to Re^4: Forks, Pipes and Exec (file descriptors)
in thread Forks, Pipes and Exec
If it is a separate thread, is there any way to have STDOUT for thread A be different from thread B?
From the activestate documentation, the STDOUT filehandle should have been duped for the child thread but I don't believe that's what I'm seeing. I can make a change in the parent to STDOUT that affects the child's STDOUT. Can anyone explain what I'm missing?
active state documentation http://www.xav.com/perl/lib/Pod/perlfork.html
"Open filehandles
Any filehandles open at the time of the fork() will be dup()-ed. Thus, the files can be closed independently in the parent and child, but beware that the dup()-ed handles will still share the same seek pointer. Changing the seek position in the parent will change it in the child and vice-versa. One can avoid this by opening files that need distinct seek pointers separately in the child."
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Forks, Pipes and Exec (file descriptors)
by BrowserUk (Patriarch) on Nov 06, 2008 at 20:48 UTC | |
I can make a change in the parent to STDOUT that affects the child's STDOUT. It depends what change you are making and how you are perceiving that the the child has been affected. In general, I do not consider Perl's Win32 fork emulation worth the effort of bothering with. There are simply too many differences between the platforms and holes in the emulation, that make *nix techniques fail to work. A few examples: Those are just a few of the limitations that come to mind. I've encountered several more anomalies that don't. IMO these difference make trying to code portable programs using fork unworkable if win32 is a target platform. If you application calls for single direction piping of data to or from the child, then using the forked-open is effective and far more portable. If you bi-directional communications between parent and child, then threads can provide an effective solution that is again, far more portable than fork. Your question to date simply asks about forking and pipes ,without giving any hint as to the actual application, so it is impossible to suggest alternatives to that approach. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
by diabelek (Beadle) on Nov 07, 2008 at 20:59 UTC | |
I'll answer some of the points you brought up first so you can point out any flaws in my thinking: From what I've read POE might have a been something to look at but I need this done sooner than later and I already have this module working in Linux... Windows is always the problem (jab). Plus I would like to get a better understanding of the inner workings of perl The last problem I seem to be fighting is that when I run the code to set a pipe as nonblocking, it isn't really nonblocking. I seem to get a chunk of data every 15 seconds or so on Win2k3 using this code: pipetest.pl
yes.pl
sample output:
| [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Nov 08, 2008 at 00:49 UTC | |
The last problem I seem to be fighting is that when I run the code to set a pipe as nonblocking, it isn't really nonblocking. I seem to get a chunk of data every 15 seconds or so on Win2k3 using this code: That problem has nothing to do with blocking. You are simply Suffering from buffering. The addition of $|++; to the top of yes.pl and you will get your output once per second. However, if the connected process is not a perl script, but some executable that doesn't disable buffering, then there may be nothing that you can do about this unless you can modify and re-build that executable. If you were using the underlying OS api calls to create the pipe, then you can disable buffering from either end, but Perl doesn't expose that functionality. If there isn't anything on the pipe that doesn't matter, I just continue and service the next request that may/may not be waiting. Select is never used so I didn't see this as an issue. Hm. Unless I am misunderstanding you, it does matter. If you try to read from a pipe and there is nothing available, then the read will block until there is. Even if the pipe is non-blocking. Which means you won't be able to "continue and service the next request" once you enter a readstate on one pipe until something becomes available on that pipe. Setting the pipe non-blocking allows you to use select to discover when the is something to be read and only enter the read when you know it will be satisfied immediately. But, I said above, there is no way to set an anonymous pipe non-blocking on win32. With respect to an alternative way to code yout application so that it will work on Win32. I'm afraid I still find your descriiption insuffucuently clear to suggest anything. There are several bit of this latest post that leave me confused. For example, I hope that explains things. Sorry, but no it doesn't. At this point, the overall architecture of your application is about as clear as mud to me. It involves child processes, and pipes, and sending commands to the children, and getting replies back, and running multiple of these concurrently, but I have no overview. And quite how you are achieving this on linux without using select is beyond me? If you have code that works on Linux and don't mind letting me see it--either here or via email--that would certainly be the quickest way for me to understand what you are doing and perhaps be able to suggest how to make it work on Win32. From what I've understood of what you've said POE certainly sounds like an option, though as you imply it would probably mean re-writing everything you have and involve a pretty steep learning curve. I'm also not sure how portable POE code is to Win32. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by diabelek (Beadle) on Nov 08, 2008 at 04:12 UTC | |
by BrowserUk (Patriarch) on Nov 08, 2008 at 15:12 UTC | |
| |
by diabelek (Beadle) on Nov 07, 2008 at 23:14 UTC | |
Time to go home for the weekend but here's a little bit more I found out. I tried to pump various amounts of data through the pipe and found that the pipe seems to complete its first read after 4096 bytes. I'm curious if there is a timeout as well that will let it complete the read. This makes me ask the question though, if I set the file handle to non blocking and Windows actually understands the non blocking, why can I only read data in after 4096 bytes have been written in? That tells me that Windows isn't doing non blocking IO but supposedly it does support it. I'll play more this weekend but if anyone has any pointers on what to look for, I'd appreciate it. I'm in the dark on this. | [reply] |