BSD Heritage & FreeBSD
macOS & BSD Internals · Operating Systems track
10 min read
In this module
The BSD Family Tree
The Berkeley Software Distribution is one of the all-time heavyweights in computing history. It started life at UC Berkeley in the 70s and 80s as a sprawling pile of patches against AT&T Unix, and somewhere in there gave us the sockets API, the TCP/IP stack, the fast file system, vi, csh, and a hundred smaller things you use every day. The BSD bloodline lives on through Darwin/XNU (and so macOS), FreeBSD, OpenBSD, and NetBSD. Knowing the family tree explains why macOS, glossy chrome notwithstanding, shares so much DNA with the same Unix lineage that produced Linux.
Dashed arrows are code flowing sideways. FreeBSD and NetBSD both rebased onto 4.4BSD-Lite after the AT&T lawsuit, and the FreeBSD-to-Darwin arrow is the one that matters for this module: macOS's BSD layer descends from NeXTSTEP, but Apple kept pulling in FreeBSD code as it went.
What macOS Inherited from BSD
XNU carries an entire BSD layer that started out as FreeBSD code. None of it is emulation or some compat shim: it's BSD kernel source compiled into XNU, though Apple has diverged from FreeBSD a long way since.
The Sockets API
The Berkeley sockets API was hammered out for 4.2BSD back in 1983 and somehow ended up the network programming interface for nearly every OS that followed:
// This code works identically on macOS, FreeBSD, and Linux// because they all implement the BSD sockets APIint sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr = { .sin_family = AF_INET, .sin_port = htons(8080), .sin_addr.s_addr = INADDR_ANY};
bind(sock, (struct sockaddr *)&addr, sizeof(addr));listen(sock, 128);
int client = accept(sock, NULL, NULL);char buf[1024];ssize_t n = read(client, buf, sizeof(buf));write(client, "HTTP/1.0 200 OK\r\n\r\nHello", 24);close(client);When Windows wanted networking, Microsoft built Winsock. They cloned the Berkeley API rather than try to reinvent it, because by then it was simply what network programmers expected.
The runner has no network, but sockets were never only about networks. socketpair() (also from 4.2BSD) hands you two already-connected Unix-domain sockets, and from then on it's the same write()/read()/close() you'd use on the TCP connection above.
The Virtual File System (VFS)
The VFS abstraction is what lets a single kernel handle wildly different file systems behind one API:
Application │ open("/path/file") ▼VFS Layer (vnode interface) │ Looks up the mount point │ Routes to correct file system ├──→ APFS driver (macOS) ├──→ UFS/FFS driver (FreeBSD) ├──→ NFS driver (network) └──→ devfs driver (/dev)VFS and vnodes came from Sun rather than Berkeley: Steve Kleiman described them in a 1986 USENIX paper on SunOS (itself a BSD derivative), and the design then propagated through every BSD variant. Linux later cooked up its own VFS layer that borrows the idea but differs in plenty of places under the hood.
POSIX Compliance
BSD systems — and macOS by extension — present a POSIX-compliant face to the world:
// These POSIX functions work on macOS, FreeBSD, and Linux:fork() // Create child processexec*() // Replace process imagewait*() // Wait for childpipe() // Create pipesignal() // Signal handlingpthread_*() // POSIX threadssem_*() // POSIX semaphoresshm_*() // POSIX shared memorymmap() // Memory mappingmacOS is a certified UNIX operating system (it has passed the Single UNIX Specification conformance tests). Linux is "Unix-like" but not certified. FreeBSD is POSIX-compliant but not certified. This means macOS provides the strongest guarantee of standards conformance, which is why many Unix programs compile on macOS with minimal changes.
FreeBSD: The Direct BSD Descendant
If you set macOS aside, FreeBSD is by far the most deployed BSD descendant. Netflix runs it on its CDN edges, Sony's PlayStation 4 and 5 are built on it, Juniper's routers are FreeBSD under the hood, and a long tail of hosting providers lean on it too.
FreeBSD Jails
Jails landed in FreeBSD 4.0 in 2000 — over a decade before Linux containers showed up:
# Create a jailjail -c name=myjail path=/jails/myjail \ host.hostname=myjail \ ip4.addr=10.0.0.2 \ command=/bin/sh
# Inside the jail:# - Own process tree (PID 1 is the jail's init)# - Own network identity (IP address, hostname)# - Own root filesystem (chrooted)# - Cannot see host processes# - Cannot access host network interfaces# - Cannot load kernel modules or modify system settingsJails vs Docker containers:
| Aspect | FreeBSD Jails | Docker (Linux) |
|---|---|---|
| Isolation | Process, network, filesystem | Namespaces (PID, net, mount, user, etc.) |
| Resource limits | RCTL (resource limits) | cgroups |
| Networking | VNET (virtual network stack) | veth pairs, bridge |
| Storage | ZFS datasets (common) | overlayfs, volumes |
| Image format | Manual or poudriere | Docker images (layered) |
| Orchestration | Manual, bastille, pot | Docker Compose, Kubernetes |
ZFS on FreeBSD
ZFS is a first-class citizen on FreeBSD. (Linux still ships it out-of-tree, courtesy of a CDDL/GPL licensing tangle that's never going to resolve.)
ZFS Features:├── Copy-on-write (like APFS)├── Snapshots and clones (like APFS)├── Built-in RAID (RAID-Z1, Z2, Z3)├── Built-in compression (LZ4, zstd)├── Data checksumming (detects corruption)├── Self-healing (with mirror/RAID)├── Datasets (lightweight file systems)├── Send/Receive (incremental replication)└── ARC (Adaptive Replacement Cache)# Create a ZFS pool with RAID-Z2 (double parity)zpool create mypool raidz2 /dev/da0 /dev/da1 /dev/da2 /dev/da3
# Create a dataset (file system)zfs create mypool/data
# Take a snapshotzfs snapshot mypool/data@tuesday
# Clone a snapshotzfs clone mypool/data@tuesday mypool/data-test
# Replicate to another machinezfs send -i mypool/data@monday mypool/data@tuesday | \ ssh backup zfs receive backuppool/dataDTrace
DTrace started life at Sun in Solaris and was later ported to FreeBSD and macOS. It does dynamic tracing across both kernel and user-space, on the fly:
# Count syscalls by process namedtrace -n 'syscall:::entry { @[execname] = count(); }'
# Trace file opensdtrace -n 'syscall::open:entry { printf("%s %s", execname, copyinstr(arg0)); }'
# Profile CPU usagedtrace -n 'profile-997 /arg0/ { @[stack()] = count(); }'Predict: what does the first one-liner print, and how would you write it on Linux?
Nothing at first. Aggregations (@[...] = count()) are collected in the kernel and only printed when you stop the script with Ctrl-C. Then you get a two-column table of process names and syscall counts, sorted with the busiest process at the bottom.
Linux has no DTrace in the mainline kernel, but bpftrace borrowed its syntax almost wholesale, so the translation is mostly a matter of probe names:
# Count syscalls by process namebpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }'
# Trace file opens (modern Linux libc calls openat, not open)bpftrace -e 'tracepoint:syscalls:sys_enter_openat { printf("%s %s\n", comm, str(args->filename)); }'execname becomes comm, copyinstr(arg0) becomes str(...), and the probes come from the kernel's tracepoints. Both tools need root.
You can hook DTrace into a running process or kernel function with no recompile and no reboot. macOS bundles it too, though SIP locks off a number of the more interesting kernel probes.
The pf Firewall
FreeBSD, OpenBSD, and macOS all use pf — short for packet filter — as their firewall:
# /etc/pf.conf# Basic pf rulesext_if = "em0" # your external interfaceblock all # Default denypass in on $ext_if proto tcp to port 22 # Allow SSHpass in on $ext_if proto tcp to port 80 # Allow HTTPpass out all # Allow outboundpf came out of OpenBSD originally and got ported over to FreeBSD and macOS. (OpenBSD also defines an egress interface group automatically, so you'll often see on egress in OpenBSD rules; FreeBSD and macOS don't have it.) The firewall you flip on in macOS's Settings app is a different thing: the per-application Application Firewall, built on socket filters. pf is there underneath, but you configure it through pfctl.
BSD code uses the permissive BSD license, which allows anyone to use, modify, and redistribute the code - even in proprietary products - without releasing source code. This is why Apple could incorporate BSD code into macOS (proprietary), Sony could use FreeBSD for PlayStation, and Netflix uses FreeBSD. Linux uses the GPL, which requires derivative works to also be open source. This licensing difference fundamentally shapes how each ecosystem's code is adopted and distributed.
How BSDs Differ from Linux
The POSIX surface looks similar enough, but the BSDs and Linux are pretty far apart in spirit:
| Aspect | BSD | Linux |
|---|---|---|
| Development | Whole-system (kernel + userland together) | Kernel separate from userland (GNU, etc.) |
| License | BSD (permissive) | GPL (copyleft) |
| Philosophy | Correctness, documentation, code quality | Features, hardware support, speed |
| Base system | Complete OS with userland | Kernel only (distros add userland) |
| Ports/packages | Ports tree (build from source) + packages | Package managers (apt, yum, pacman) |
| Init system | rc.d (simple shell scripts); launchd on macOS | systemd (most) / OpenRC / runit |
| Filesystem | ZFS (native), UFS | ext4, btrfs, XFS |
| Networking | pf firewall | netfilter/nftables |
| Containers | Jails (2000) | Namespaces + cgroups (2013) |
Building the kernel and userland together as one project gives the BSDs a consistency that's genuinely hard to fake — uniform docs, a coherent style, fewer surprises. Linux's split between an upstream kernel and a hundred distributions delivers richer hardware support and faster feature churn, at the cost of a thousand papercuts when systems diverge.
Knowing the BSD lineage demystifies a lot: why certain APIs are shaped the way they are, why macOS happily runs grep and awk, and how the same OS concepts can land in radically different forms. Watch the industry long enough and BSD's fingerprints keep surfacing — jails became containers, ZFS keeps reappearing in serious storage stacks, DTrace inspired eBPF, and pf still sets the bar for firewall syntax.