in reply to Re^8: Forks, Pipes and Exec (file descriptors)
in thread Forks, Pipes and Exec
I can definitely change the buffering on the other application and that helps a bit.
As for the non-blocking, I thought non-blocking allowed a read to complete even when there was no data. If there was no data, I thought either EOF or EAGAIN or something was set. The example above can be changed to this to get it working in linux and loop as fast as possible.
use IO::Handle; use Timer::HiRes qw(usleep); print "before the pipe\n"; sub getpipe { my $hash2 = shift; print( "starting yes.pl " . time() . "\n" ); $hash2->{pid} = open( $hash2->{stdout}, "/usr/bin/perl yes.pl |") o +r die; $hash2->{buffer} = ""; $hash2->{stdout}->blocking(0); sleep( 1 ); return $hash2->{pid}; } my $hash = {}; getpipe($hash); my $fh = $hash->{stdout}; print( "pipe created\n" ); my $count = 0; while( 1 ) { my $data = <$fh>; if( $data != "" ) { print "got from pipe: $data"; } print( "." ); usleep( 10000 ); } print( "done\n" );
I will try to post the script externally and provide a link so you understand what I'm trying to do a little better. To answer a couple of your questions about threads/processes, I'm really using both. I start the thread/process by calling fork. So in Linux, I understand that I'm using the true fork command. In Windows, I'm using the pseudo fork that is really thread when you get to the bottom of things. Which one I use doesn't matter. I just need a separate branch of execution so the parent script can continue doing its normal thing while my branch of execution handles the external processes. Thats probably an ignorant statement but that's why I'm posting :)
I've found another perl script that sounds like what I'm doing: logtail. I believe the basic idea is the same. I need to review the code more to see what they have done.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Forks, Pipes and Exec (file descriptors)
by BrowserUk (Patriarch) on Nov 08, 2008 at 15:12 UTC | |
by diabelek (Beadle) on Nov 12, 2008 at 04:05 UTC | |
by BrowserUk (Patriarch) on Nov 12, 2008 at 05:45 UTC | |
by diabelek (Beadle) on Nov 12, 2008 at 15:46 UTC | |
by BrowserUk (Patriarch) on Nov 12, 2008 at 21:39 UTC |