open() vs the lowest unused file descriptor

Ryan Sommers ryans at gamersimpact.com
Sat Oct 16 07:50:50 PDT 2004


Carl J wrote:

> Hi!
>
> Today I noticed that on Single Unix Specification V2,
> as well as on the Linux 2.4.26 machine I have here,
> that the open() call promises to return the lowest
> unused file descriptor when successful.
>
> I'm just wondering: does FreeBSD 4.x and 5.x promise
> that? If so, should we update the manpage
> to match SUSv2 more closely?
>
> Thank you!
>
> - Carl


4.x I'm pretty sure about 5.x I know does. This isn't a new thing. Since 
as far back as I can remember the UNIX semantics have been to return the 
lowest unused fd on an open(2) call. This has also been the subject of 
much discussion as finding the first free descriptor can cost a lot of 
processing power for applications that use large numbers of descriptors. 
FreeBSD uses a bitmap with hints I believe. All code would be in 
sys/kern_descrip.c.

-- 
Ryan Sommers
ryans at gamersimpact.com



More information about the freebsd-hackers mailing list