[Nottingham] Re: AAaaargh! Bash and & and ; and () ...

Martin martin at ml1.co.uk
Thu Jan 26 21:41:53 GMT 2006


Martin wrote:
[...]
>>> After some very convoluted lost hours:
>>>
[...]
>> Is there something 'strange' about redirecting named pipes?!
[...]
> You might also get an error about "System call interrupted" for that 
> problem...
> 
> 
> Any better solutions for:
> 
> for ...
> do
>   ( sleep 10 ; write >named_pipe ) &
> 
>   lots of processing
> 
>   { read } <named_pipe
> done
> 
> that guarantees good timing? (not cron!)
> 
> 
> Time for a beer!

Well, a few beers later and the solution is:


exec 6<> named_pipe

for ...
do
    (
	sleep 10 ; echo "#" >6
    ) &

    lots of processing

# Wait for the 10 seconds to be up
    read -u 6 k
done

exec 6<&-


The "System call interrupted" errors were likely a consequence of how 
bash (sometimes!) creates child processes for loops and code 
blocks/brackets and then getting a timing race for how those child 
processes terminate and what state the file descriptor is in at that 
instant before the next write...


All good subtle stuff. No wonder The Hurd (GNU kernel) is still being 
hacked some 25 years later!!!


Anyone want a talk on this?

Cheers,
Martin

-- 
----------------
Martin Lomas
martin at ml1.co.uk
----------------



More information about the Nottingham mailing list