FreeBSD System Programming

Copyright(C) 2001,2002,2003,2004 Nathan Boeger and Mana Tominaga

I. Introduction

BSD is a family of operating systems based on what originated as a distribution of changes and enhancements to AT&T's Unix operating system. The complex history of BSD itself is recounted by key kernel developer Marshall Kirk McKusick in his essay collected in "Open Sources: Voices from the Open Source Revolution" (O'Reilly, 1999). It is a comprehensive survey of the technical and historical details surrounding the birth of one of the most popular open source projects ever. The entire chapter is available online at:

In summary, the BSD family of operating systems dates back to the late 1970s, when AT&T owned Unix. Although Unix was proprietary, source code was available, which encouraged customers to make modifications to their systems. One such customer was the University of California at Berkeley's Computer Systems Research Group. Their version of Unix was known as the Berkeley System Distribution (BSD). BSD tapes were available for a nominal fee to anyone with a Unix source license. BSD received a big boost from the United States Department of Defense, who selected BSD as the base system for implementing TCP/IP and what became the Internet. The TCP/IP code was made freely redistributable via Networking Release 1 (Net/1) in 1989.

Originally, BSD required an AT&T Unix system and source license to build and run; but in time, BSD code had almost completely supplanted every subsystem of the Unix OS, turning into a standalone OS. A nearly complete BSD system, free of AT&T code, was released as Networking Release 2. Net/2, released in 1991, was only six files short of a complete system and was freely redistributable. A distribution called 386/BSD soon emerged, which had replaced those six files. Ongoing development of 386/BSD was limited; several forks quickly emerged, including NetBSD, FreeBSD, both free software, and the commercial BSDI.

In 1992, AT&T's Unix Systems Laboratories (USL)sued BSDI and the University of California, alleging the use of proprietary AT&T code and intellectual property in both BSDI and Net/2. A 1994 settlement resulted in the release of a modified version of Net/2 called 4.4BSD-Lite. Any project based on this release would be immune from litigation by USL, which by then was owned by Novell. As a result, NetBSD, FreeBSD, and BSDI all redeveloped their systems to use the 4.4BSD-Lite code base. After one more release in 1995, 4.4BSD-Lite Release 2, the CSRG closed down for good. BSD development, post-CSRG, has splintered off into several distinct varieties. Although the development model (one core; many iterations) resembles that of Linux, the various branches of the BSD family are much more distinct than the various Linux distributions. The best-known among these are FreeBSD, OpenBSD, NetBSD, and Darwin. They are all under active development, and are freely available with source code to all. FreeBSD development was originally centered on the x86 platform and aims for maximum performance. NetBSD aims for portability (runs on virtually every platform extant) and elegance, with an eye towards embedded systems. OpenBSD, a more recent fork of NetBSD, stresses security through a code audit process and integration of cryptography. The core of Apple's OS X, Darwin, is basically a BSD system on top of a Mach microkernel, which dates back to NeXTStep.

FreeBSD is a highly sophisticated operating system designed for the x86 compatible, DEC Alpha, and PC-98 architectures. It is optimized for Internet and intranet servers, with strong networking and security features. Additional ports to platforms such as PowerPC and Sparc64 are in the works. Among the free BSDs, FreeBSD enjoys the widest deployment, with highly visible commercial customers such as Yahoo. Software packages are also numerous - at the time of writing, 7883 applications had been ported to FreeBSD. And, if there is a program available for Linux, FreeBSD's Linux compat support lets you run many Linux programs almost natively.

FreeBSD is often praised for its technical simplicity. For example, its installation program is widely regarded as the simplest Unix installer around, and the Ports Collection is an extremely elegant systemwhich combines pristine sources with FreeBSD-specific patches to build and install additional software. At the time of writing, almost 8000 software packages are available through the Ports Collection. Both NetBSD and OpenBSD have adopted the Ports Collection to manage additional software, though neither enjoy the sheer number of applications available. FreeBSD's development model exemplifies that of BSDs. It is highly centralized, and with a clear hierarchy. There's a group of more than two hundred developers called committers, who can make any change to the official FreeBSD source code whenever. The committers are chosen by the core team, a select group of the committers, chosen by from themselves. Elections are held every other year.

While FreeBSD focused development efforts on the 386, others started porting BSD to other platforms, notably the Macintosh, at Virginia Tech. Efforts soon expanded to Atari ST, Amiga, and PC platforms. As FreeBSD increasingly focused on a deep operating system optimized for i386, NetBSD began picking up the development efforts for other platforms. As of this writing, NetBSD supports the widest range of platforms for a BSD branch. And, its also notable for the range of exotic hardware supported, such as the short-lived Sega Dreamcast game console. NetBSD also enjoys commercial backing of Wasabi Systems, a company founded by one of the NetBSD developers, for porting NetBSD to new microprocessors and systems.

OpenBSD was founded by NetBSD SPARC port lead Theo de Raadt after a disagreement between de Raadt and the core team over future development direction. OpenBSD's first release came in October 1996, with a focus on security. Because OpenBSD is based in Canada (de Raadt lives in Calgary), it isn't encumbered by U.S. export regulations. As a result, cryptographic software is integrated into the base system. OpenBSD developers also created OpenSSH, a free implementation of the popular SSH encryption protocol. OpenSSH quickly displaced the commercial free-for-noncommercial-use SSH software. When you first install OpenBSD, it feels bare compared to FreeBSD; many networking features are turned off by default to avoid potential security holes.

Darwin, unlike the other three mentioned above, is licensed under the Apple Public Souce License. It compels that you forgo patent rights on any invention that uses the code. Apple only can build commercial software using it. It is notable in providing a wider user base for BSD, but most in its gorgeous Aqua GUI, which is years ahead of X Windows in terms of usability, customizability, and overall graphic sophistication.

Although this book focuses on FreeBSD, many of the concepts discussed will apply to other BSDs. (If there iss an exception, it will be noted.) The authors choose FreeBSD for not only its technical merits, but also for its excellent documentation. In addition to the usual man pages, The FreeBSD Handbook is a detailed, extensive how-to manual written by the developers and users.

II. Why BSD?

Many developers focus on just their particular BSD branch niche but a good chunk run in multiple circles. As such, you can pick and choose areas of interest, and development work may end up getting multiple layers of review, from other distributions that not only port the code but test it as well. For example, with security issues, often bug fixes are common across the BSDs. And even with the Linux world, there is constant borrowing, particularly for driver code. From a technology perspective, BSD embraces a number of sophisticated design considerations that make it a cutting edge operating system for admins and programmers alike, most of which are outlined in other resources, most notably the comprehensive book Absolute BSD, by Michael Lucas. The most notable non-technical fact about BSD is its licensing: BSD is certified under a truly free license, so anyone can do whatever she wants with the code, licensing it and making a profit, or using portions as part of a larger work. What restrictions exist apply to the developer's scope of responsibility - a previous developer can't be held liable for errors, for example. As such, BSD code is all around us. Take the rise of the Internet, which relies heavily on TCP/IP, networking code born of BSD. If administrators had to reinvent the wheel, the Internet's ubiquity in our lives wouldn't have happened as quickly.

III. Who this book is for

This book is intended as a resource to system programming on BSDs. The reader should be familiar with basic programming in C or C++. The reader does not need to have system administration knowledge. System administration skills would be useful, however, for creating a good development environment. For Futher Reading:

A Brief History of FreeBSD:
The FreeBSD Handbook:

IV. About the Authors

C, C++, Java developer and senior sys admin, Nathan Boeger has been using FreeBSD since 1.x . Nathan has worked at various companies as sys admin and developer, including GetRelevant, Redline Networks, and Penguin Computing. He is currently getting ready for graduate school, and lives in New York, NY.

Mana Tominaga is a technology editor and writer, covering the Internet industry since late 1998. She has written and edited product reviews at Fawcette Technical Publications, for VBPJ and, and at CMP Media for Web Techniques magazine, later known as New Architect. Mana has a degree in English literature from the University of California at Berkeley, and lives in San Jose, CA.

FreeBSD System Programming