SPUG: shell script event loops + wrapping shell utilities
dancerboy
dancerboy at strangelight.com
Sun Apr 21 00:44:08 CDT 2002
At 4:20 pm -0700 2002-04-20, Andrew Sweger wrote:
>On Sat, 20 Apr 2002, dancerboy wrote:
>
>> And added this to the loop:
>>
>> > select( $rin, undef, undef, undef );
>>
>> But this just blocked forever, even when there was definitely input
>> on TTY.
>
>select($rin, undef, undef, 0);
>
>Having that undef as the timeout means "block until we have something to
>read".
Hmmm... was my post not clear? This is exactly what I *wanted*:
"block until we have something to read". The problem is, it seems to
continue blocking *even when there IS something to read*. The select
call never returns, ever, no matter what, and the input just keeps
piling up in the buffer until I manually kill the process (at which
point the calling shell gets the input that was intended for the Perl
script -- which can have "interesting" results, depending on what I
was typing...)
> If your application can stand a little idle time in the event loop
>(if it's primary job is waiting for input), it won't hurt to put a timeout
>value greater than zero in. This will reduce the amount of CPU time your
>application will burn too.
>
>select($rin, undef, undef, 0.01); # 10ms timeout
As I said, this is exactly what I did:
select( undef, undef, undef, 0.1);
because that was the *only* way that the select call would *ever*
return. (And since it was invariably waiting until the timeout, it
didn't matter what I put as the first argument.)
>
>(select() is one of those really cool functions that twists your brain
>around the fork tines the first few times, then it's just fun. Do *not*
>mix with buffered IO!)
The concept doesn't seem difficult -- my problem is that as far as I
can tell, it's not behaving as documented. And I'm not using
buffered I/O -- all my input is done with sysread.
-jason
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list