SPUG: shell script event loops + wrapping shell utilities

Andrew Sweger andrew at sweger.net
Sat Apr 20 18:20:06 CDT 2002


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". 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

(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!)

-- 
Andrew B. Sweger -- The great thing about multitasking is that several
                                things can go wrong at once.



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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