[plug] shell non-blocking i/o

Russell Steicke r.steicke at bom.gov.au
Sun Dec 8 23:24:14 WST 2002


Hi,

I want to do non-blocking output from a shell script.  (And I'd rather
not write a perl or python script to do this...)

The situation is: I have a FIFO in the filesystem that is used to
trigger a process to do something.  The process sleeps and waits for a
byte to be written to the fifo (the process is actually waiting in
select(2)), and wakes up when any byte is written.  But that process may
sometimes not be there, and that's a normal situation.  In that case I
want the process that writes the trigger byte to just realise that and
continue on its way.

In C, perl or python I can open the fifo in non-blocking mode
(O_NDELAY), and the return from write() will tell me whether anything
was written or not.

Is there a way to do this in shell code?

  echo > trigger_fifo

where trigger_fifo is a FIFO, and the echo does not block if
trigger_fifo has no reader.  I don't actually need to know if anything
was really written, I just don't want the script to block.

bash doesn't seem to be able to do non-blocking io, and a browse through
the zsh man pages didn't turn up anything obvious.  Google wasn't much
help, but I'm not the best googler around.

I'd rather avoid having another C program (echo_byte_to_fifo.c) hanging
around to do that, but it may be the easiest way:

  echo_byte_to_fifo trigger_fifo

Any ideas?  Can any shell do this natively?

TIA


-- 
Russell Steicke

-- Fortune says:
Beware of a dark-haired man with a loud tie.



More information about the plug mailing list