Datasheet
The Kernel
The heart of a Unix operating system is its kernel. The kernel is the program that loads when the com-
puter is first turned on and is responsible for managing all the hardware resources available to the com-
puter. The kernel is also responsible for running the other programs on the system, scheduling process
execution so that they can share the central processing unit (CPU) and other resources, and preventing
one process from seeing what another process is doing. These last two responsibilities are more com-
monly known as pre-emptive multi-tasking and protected memory, respectively.
Because Unix prevents programs from accessing the computer hardware or other programs directly, it
protects against the most common forms of system crashes. If a process misbehaves in one way or
another, the system simply terminates the process and continues on its way. In other words, the misbe-
having process crashes. In some operating systems, a misbehaving process can stomp all over other
applications, or even break the operating system itself, before the system is able to terminate the process.
As a result, poorly written programs can cause the entire computer to freeze or crash. Not so on Unix;
because a process cannot modify other processes, including the kernel, there is virtually no risk of a bad
process bringing down the entire operating system.
Although the kernel is responsible for accessing hardware, much of the knowledge of specific hardware
details is delegated to device drivers. Device drivers are small programs that are loaded directly into the
kernel. Whereas the kernel might know how to talk to hard disks, for example, in general, a specific
device driver knows how to talk to specific makes and models of hard disks. This provides a way for
third parties to add support for new devices without having to build it into Apple’s kernel. Mac OS X
includes default drivers for talking to a wide variety of devices, so much of the time you won’t need to
install separate drivers when you install new third-party hardware.
The System Library
The kernel is responsible for critical functions such as memory management and device access, so pro-
grams must ask the kernel to perform work on its behalf. Programs communicate with the kernel
through an application program interface (API) provided by a special library. This library defines some
common data structures for describing system operations, provides functions to request these opera-
tions, and handles shuttling data back and forth between the kernel and other programs. This library is
simply called the system library.
As you might imagine, every program on Mac OS X links against this library, either directly or indirectly.
Without it, a program would be unable to allocate memory, access the file system, and perform other
simple tasks.
8
Chapter 1
What Is an API?
All libraries and frameworks provide a collection of functions and data structures that
programs can use to perform a task. For example, the system library provides func-
tions for reading from files; QuickTime provides functions for playing back QuickTime
movies. These functions and data structures are collectively known as the library’s
application program interface, or API.
05_573993 ch01.qxd 6/16/05 2:22 PM Page 8