Advanced shell scripting question :-)

Kevin D. Clark kclark at CetaceanNetworks.com
Thu Sep 5 14:24:23 EDT 2002


"Derek D. Martin" <ddm+gnhlug at pizzashack.org> writes:

> The bf file is a total mess; using select() does not allow you to say
> "give me the input from each file descriptor, in the order you
> received it" as far as I can tell...  And because of this, there's no
> way (AFAICT) to order your output to your output file in the same
> order it came in.  However if the output to the screen is
> satisfactory (despite being out of order), one could duplicate it in a
> file using the normal "> file 2> file" and then "tail -f file" to get
> the output to the screen.
> 
> What I'm wondering is: there's got to be a way to do this, such that
> the output is syncronized to the order of the input, doesn't there?
> The operating system does (more or less) this all the time, whenever
> it sends stdout and stderr to your terminal.
> 
> Any I/O gurus out there know by what mechanism this could be achieved?
> I'm now very curious...  

You can't do with with any of the standard i/o multiplexing facilities
(select(), poll(), etc.)

You could do this with threads, in a fashion.

However...

> It seems to me this probably not the only
> sort of application where you might want to process the input from
> several descriptors in the order it was received.

...most of the descriptors that I deal with are connected to things
that are influenced by a certain degree of randomness (the randomness
of a network, the randomness of a OS's scheduler, etc.).  Because of
this, I never find myself architecting a program that would call of
this sort of capability -- it'd be non-sensical.

--kevin
-- 
Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA)
cetaceannetworks.com!kclark (GnuPG ID: B280F24E)
alumni.unh.edu!kdc




More information about the gnhlug-discuss mailing list