Yep. Maybe fewer programs, but a significant number never the less. As
I said, this behaviour is built into shell scripts all over the place.
> > A newly execd program could reasonably expect this to work:
> >
> > int main()
> > {
> > int fd = dup(2);
> > assert(fd == 3);
> > ...
Actually, this example is wrong. If it were started with fd 3 already
open (a.out 3> /dev/null), the assert would fail anyway.
> so the real breakage is: applications cannot expect to get first-free ID
> >= 3 when _reusing_ file IDs. Eg. an application allocates all files from
> 0 to 100, then frees 97, 51 and 77, and expects the next open() to give ID
> 51.
I can assure you there's programs out there which presume this will
work. Rememer that ld.so does lots of things to fds before main is
called; similarly, unknown things happen inside libraries. A program
can't assume any fixed behaviour from your scheme, regardless of what
stage of execution its in.
On the other hand, I might be wrong. Try it, and see what happens; if
things break, you've got (most) of the source.
J