#! perl -slw use strict; use threads; use Thread::Queue; $|=1; sub tail { my( $file, $Q ) = @_; my $pid = open TAIL, "u:tail --follow=name $file |" or die $!; print "pid:$pid"; END{ kill 9, $pid } while( ) { $Q->enqueue( $_ ); } } my $Q = new Thread::Queue; my $t = threads->new( \&tail, $ARGV[ 0 ], $Q ); while( sleep 1 ) { print 'Here'; printf "Got: %s", $Q->dequeue() while $Q->pending; } #### ## Create a file to tail P:\test>start /b perl -le"$|=1; select( undef, undef, undef, 0.1 ), print $_, '-'x100 for 1 .. 10000;" > tmp\log P:\test>387706 tmp\log pid:276 Here Here Here Here Got: 11---------------------------------------------------------------------------------------------------- Got: 12---------------------------------------------------------------------------------------------------- Got: 13---------------------------------------------------------------------------------------------------- Got: 14---------------------------------------------------------------------------------------------------- Got: 15---------------------------------------------------------------------------------------------------- Got: 16---------------------------------------------------------------------------------------------------- Got: 17---------------------------------------------------------------------------------------------------- Got: 18---------------------------------------------------------------------------------------------------- Got: 19---------------------------------------------------------------------------------------------------- Got: 20---------------------------------------------------------------------------------------------------- Got: 21---------------------------------------------------------------------------------------------------- Got: 22---------------------------------------------------------------------------------------------------- Got: 23---------------------------------------------------------------------------------------------------- Got: 24---------------------------------------------------------------------------------------------------- Got: 25---------------------------------------------------------------------------------------------------- Got: 26---------------------------------------------------------------------------------------------------- Got: 27---------------------------------------------------------------------------------------------------- Got: 28---------------------------------------------------------------------------------------------------- Got: 29---------------------------------------------------------------------------------------------------- Got: 30---------------------------------------------------------------------------------------------------- Got: 31---------------------------------------------------------------------------------------------------- Got: 32---------------------------------------------------------------------------------------------------- Got: 33---------------------------------------------------------------------------------------------------- Got: 34---------------------------------------------------------------------------------------------------- Got: 35---------------------------------------------------------------------------------------------------- Got: 36---------------------------------------------------------------------------------------------------- Got: 37---------------------------------------------------------------------------------------------------- Got: 38---------------------------------------------------------------------------------------------------- Got: 39---------------------------------------------------------------------------------------------------- Got: 40---------------------------------------------------------------------------------------------------- Got: 41---------------------------------------------------------------------------------------------------- Got: 42---------------------------------------------------------------------------------------------------- Got: 43---------------------------------------------------------------------------------------------------- Got: 44---------------------------------------------------------------------------------------------------- Got: 45---------------------------------------------------------------------------------------------------- Got: 46---------------------------------------------------------------------------------------------------- Got: 47---------------------------------------------------------------------------------------------------- Got: 48---------------------------------------------------------------------------------------------------- Got: 49---------------------------------------------------------------------------------------------------- Here Here Here Here Got: 50---------------------------------------------------------------------------------------------------- Got: 51---------------------------------------------------------------------------------------------------- Got: 52---------------------------------------------------------------------------------------------------- Got: 53---------------------------------------------------------------------------------------------------- Got: 54---------------------------------------------------------------------------------------------------- Got: 55---------------------------------------------------------------------------------------------------- Got: 56---------------------------------------------------------------------------------------------------- Got: 57---------------------------------------------------------------------------------------------------- Got: 58---------------------------------------------------------------------------------------------------- Got: 59---------------------------------------------------------------------------------------------------- Got: 60---------------------------------------------------------------------------------------------------- Got: 61---------------------------------------------------------------------------------------------------- Got: 62---------------------------------------------------------------------------------------------------- Got: 63---------------------------------------------------------------------------------------------------- Got: 64---------------------------------------------------------------------------------------------------- Got: 65---------------------------------------------------------------------------------------------------- Got: 66---------------------------------------------------------------------------------------------------- Got: 67---------------------------------------------------------------------------------------------------- Got: 68---------------------------------------------------------------------------------------------------- Got: 69---------------------------------------------------------------------------------------------------- Got: 70---------------------------------------------------------------------------------------------------- Got: 71---------------------------------------------------------------------------------------------------- Got: 72---------------------------------------------------------------------------------------------------- Got: 73---------------------------------------------------------------------------------------------------- Got: 74---------------------------------------------------------------------------------------------------- Got: 75---------------------------------------------------------------------------------------------------- Got: 76---------------------------------------------------------------------------------------------------- Got: 77---------------------------------------------------------------------------------------------------- Got: 78---------------------------------------------------------------------------------------------------- Got: 79---------------------------------------------------------------------------------------------------- Got: 80---------------------------------------------------------------------------------------------------- Got: 81---------------------------------------------------------------------------------------------------- Got: 82---------------------------------------------------------------------------------------------------- Got: 83---------------------------------------------------------------------------------------------------- Got: 84---------------------------------------------------------------------------------------------------- Got: 85---------------------------------------------------------------------------------------------------- Got: 86---------------------------------------------------------------------------------------------------- Got: 87---------------------------------------------------------------------------------------------------- Got: 88---------------------------------------------------------------------------------------------------- Here Here Terminating on signal SIGINT(2)