== BSD Unix developed over more time than I usually think Left to myself, I tend to sloppily think of 4.2 BSD as where all of the major development of BSD Unix took place and the point in time where what we think of as 'BSD Unix' formed. Sure, there were BSDs before and after 4.2 BSD, but I think of the before releases as just the preliminaries and the releases after 4.2 BSD as just polishing and refining things a bit. As I was reminded today, this view is in fact wrong. If you'd asked me what 4.x BSD release _inetd_ first appeared in, I would have confidently told you that it had to have appeared in 4.2 BSD along with all of the other networking stuff. Inetd is such a pivotal bit of the BSD networking (along with the services that it enables, like _finger_) that of course it would be there from the start in 4.2, right? Wrong. It turns out that _inetd_ only seems to have appeared in 4.3 BSD. In fact a number of related bits of 4.2 BSD are surprisingly under-developed and different from what I think of as 'the BSD way'. Obviously, _finger_ in 4.2 BSD is not network enabled, but a more fundamental thing is that *4.2 BSD limits processes to only 20 open file descriptors at once* (by default, and comments in [[the source http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/h/param.h]] suggest that this cannot be raised above 30 no matter what). Instead it is 4.3 BSD that introduced not just _inetd_ but a higher limit on the number of open file descriptors ([[normally 64 http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.3BSD/usr/src/sys/h/param.h]]). With that higher limit came the modern ((FD_*)) set of macros used to set, check, and clear bits in the _select()_ file descriptor bitmaps; 4.2 BSD didn't need these since the file descriptor masks fit into a single 32-bit word. (I discovered this due to [[a Twitter conversation with Mark Jason Dominus https://twitter.com/mjdominus/status/615242843267944448]]. I now think my initial answer is almost certainly wrong, but that's going to be [[another entry SocketReturnAPIDesign]].) === Sidebar: _dup2()_ and BSD's low file descriptor limit Given the existence of the _dup2()_ system call, which in theory lets you create a file descriptor with any FD number, you might wonder how 4.2 BSD got away with a 32-bit word for the _select()_ bitmask. The answer turns out to be that 4.2 BSD simply forbid you from _dup2()_'ing to a file descriptor number bigger than 19 (or in general the _NOFILE_ constant). (You can see the code for this in [[the _dup2()_ implementation http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/kern_descrip.c]]. In general a lot of the early Unix kernel source code is quite simple and readable, which is handy at times like this.)