Table of Contents

  1. Introduction
  2. History
  3. Naming
  4. Underpinnings
  5. GUI
  6. Package Management
  7. Applications and Libraries
  8. Daemons and Services
  9. Networking
  10. Searching
  11. Mac OS X at the Command Line
  12. For Developers
  13. Further Reading
  14. Questions?
  15. References
  16. Revisions

Introduction

Apple Computer's Mac OS X is one among the hundreds of Unix-based operating systems. It is similar to “common” Unices in some ways, and vastly different in others. Linux users may be interested in exploring Mac OS X to explore another common flavor of Unix, and they'll find that in many ways it is the same, but in some it is very, very different.

This presentation is written with users familiar with basic Linux concepts in mind. It addresses some advanced subjects, but a basic understanding of Linux is helpful in understanding the features discussed here. This presentation approaches Mac OS X from a technical angle; it doesn't go into detail about the user experience or available software unless it differs significantly from the “traditional” way of doing things on Linux and Unix.


History

Mac OS X was first released in 1999 in the form of Mac OS X Server 1.01. It looked very much like earlier releases of the “classic” Mac OS, but underneath it was based on something very different: Unix. About two years later, Mac OS X was released for Apple's desktop systems with a new look and new features. Several versions of Mac OS X have been released since that time, most recently Mac OS X 10.4 “Tiger” in 2005.

The Unix underpinnings of OS X are derived from the Unix-based NeXTstep (also known as NextStep, NeXTSTEP, NEXTSTEP, OpenStep, and OPENSTEP), created by NeXT Computer, a company founded by one of Apple's founders after he departed the company in 1985. NeXTstep included a number of features revolutionary at the time of its introduction including system-wide drag and drop, system-wide piped services, 3D widgets, and other features common today2. NeXT was purchased by Apple in 1997, and NeXTstep became the foundation of Mac OS X.

Before acquiring NeXT, Apple explored the possibility of buying Be Incorporated to build a next-generation Mac OS based on the BeOS operating system.


Naming

Like the pronunciation of Linux, there are differing opinions on the pronunciation of Mac OS X. Officially, its name is pronounced “Mac OS Ten.” This gets more confusing with version numbers: Mac OS X 10.4 “Tiger,” for instance. Conventions on pronouncing the name with its version number are less clear. One common way is to say, “Mac OS Ten Point Four ‘Tiger.’” That is the convention this presentation will follow.


Underpinnings

Basics

The Unix core of Mac OS X is an operating system called Darwin. It is open source, distributed under the Apple Public Source License, which has been approved by OSI but is not GPL-compatible3.

Darwin is BSD-based and includes common Unix utilities and features. It is available independently of Mac OS X, most prominently through the OpenDarwin project.

Kernel

The kernel of Mac OS X is called XNU. It is based on the Mach microkernel, with BSD Unix components grafted onto it (primarily from FreeBSD). Each new release of Mac OS X includes a new version of XNU much like most new releases of Linux-based operating systems include new versions of Linux — the kernel version in Mac OS X 10.4.2 is 8.2.0.

XNU is modular, with extensions that can be loaded at runtime (called “kernel extensions,” with a .kext file extension) much like Linux's kernel modules. Most device drivers are distributed at .kext files. In XNU version 8.0, Apple introduced a stable binary interface for kernel extensions to ensure future support of older drivers without recompilation. (Contrast this to Linux, which has no stable binary interface for modules and often requires modules to be recompiled based on kernel version.)

The XNU kernel supports three types of threads: Mach threads (the fundamental thread type), POSIX threads (“pthreads”), and Carbon threads (primarily for programs designed for the legacy Mac OS). POSIX and Carbon threads are mapped onto Mach threads for execution.

Binaries running on XNU are distributed in the Mach-O binary format. Mac OS X cannot execute ELF binaries. (Interestingly, BootX, the OS X bootloader on PowerPC, does support ELF binaries and ext2 filesystems, theoretically allowing someone to boot Linux using the default bootloader4.)

Filesystems

Mac OS X can run on two file systems: HFS (with variant HFS+) and UFS (a variant of the Fast File System from the BSD world). Most installations of the operating system use HFS+, an extended version of the filesystem used on Macintosh computers for many years. In OS X 10.3, journaling support was added to HFS+, and OS X 10.4 added new support for arbitrarily extensible metadata in the filesystem5. Default installations on HFS+ volumes are case-insensitive, but a disk can be formatted case-sensitive at install time. All of the Unix-derived software running on the OS supports the case-sensitive mode well, but some third party software, especially legacy applications, will break when the filesystem is formatted in case-sensitive mode.

Access Control Lists (ACLs) are also supported by Mac OS X, but not enabled by default6.

In addition to UFS and HFS+, Mac OS X supports various other filesystem types including7:


GUI

While many Unix variants use X-Windows for graphics, Mac OS X uses a different graphics system called Quartz. It is PDF-based, and in OS X versions 10.2 (“Jaguar”) and above, an updated system called Quartz Extreme renders all windows as OpenGL textures and uses the features of compatible video cards to provide a smoother experience.

The user-facing side of the display system is called Aqua. It is characterized by light colors, shiny widgets, and very smooth text rendering. In past versions of OS X, pinstripes were common, but with each successive version they have become less prevalent.

Toolkits

Much like Linux, Mac OS X has different graphics toolkits for applications to use. Unlike GTK and Qt, both of Mac OS X's toolkits have the same outward appearance and, to the casual user, are mostly indistinguishable. These toolkits are descended from two sources.

The Cocoa toolkit is based on APIs imported from NeXTstep. It is regarded by programmers as being very powerful and elegant. Applications using Cocoa are generally written in Objective-C, although there are bindings for other languages including Java, Python, and C#. The official OS X web browser, Safari, uses Cocoa libraries.

The Carbon toolkit is derived from legacy APIs from the classic Mac OS. It made porting software from Mac OS 9 and earlier easy for developers. The OS X Finder uses Carbon libraries.

X11

Even though OS X doesn't use X-Windows, Apple provides a port of Xorg that runs on top of OS X and allows for X-based software to run on Mac OS X. It can operate with a root window or in rootless mode, and a window manager called aqua_wm is included to provide Aqua titlebars and integrate more cleanly into the Mac OS X environment.

Many ported programs use Apple X11 for display output instead of using Cocoa or Carbon natively. The official OpenOffice.org release for OS X uses X11, as does MATLAB.

Xorg runs under Darwin and can be used for graphics on Darwin installations.


Package Management

There are several package management options for Mac OS X and Darwin. No package managers are bundled with the operating system by default. Available package managers include:

Package managers on Mac OS X typically keep an inventory of the packages installed with the base OS X installation and store any updates separately to allow OS X's Software Update tool to work unhindered.


Applications and Libraries

As a full-fledged Unix-based operating system, Mac OS X bundles many standard utilities and libraries. “Typical” users seldom see these things. The standard configure, make, make install procedure generally works to install software designed for Unix systems, but typical users aren't going to be bothered to use this method (or package managers) to install software. There are two standard methods of software installation on Mac OS X: the Application Bundle and the Installer.

Software for OS X is usually distributed in a .dmg file, which is a compressed disk image. The user double-clicks the file (or selects it and uses a menu to open it), and it is mounted automatically with either the “app bundle” or installer located inside, generally with documentation also included.

From here, the process diverges depending on the way that the application being installed is distributed.

Application Bundles

If the program is distributed as an app bundle, the process is as simple as dragging the bundle from the disk image into the Applications folder in the Finder (or to whatever directory the user prefers to store the bundle in). To users, the app bundle is the application. When it is double-clicked, the application launches.

In reality, an application bundle is a directory (with a name ending in .app) that contains the binary and any support files such as non-standard libraries, resources like images and sounds, shell scripts, and any other necessary files to allow the program to run. When it is opened, the operating system references a property list file inside the bundle to determine what needs to be done to launch the binary.

Application bundles are the preferred method of software installation for Mac OS X. They are easy for the user to manage and easy to uninstall (just drag the bundle into the trash can).

Installers

If an application needs to make deeper changes to the operating system, it may be bundled with an installer. Installers are more difficult to work with than app bundles and their use is discouraged if they are not necessary. Some developers still insist on using them, but a majority of programs for Mac OS X do not install themselves this way. Programs that need to install a kernel extension, like printer and scanner drivers, generally use installers.

Apple includes an installer that can load developers' packages with the operating system. Using this helps with consistency, since any installation that uses it is using a familiar program with consistent conventions to handle its job. Some applications are installed using third-party installation tools, especially those written for Mac OS 9 and earlier and ported to OS X later in life.

User Preferences (“dot files”)

Each user in Mac OS X has a Library directory inside of their home directory that contains their settings and any other files that programs need to store to maintain state. The Application Support directory, specifically, is intended to contain the information that standard Unix programs most often store in “dot files.” Programs create a directory inside of Application Support and store their settings there. (Some Unix programs ported to Mac OS X do continue to store settings in dot files in ${HOME}, including bash.)

Native applications generally use a Property List file to store their settings, with an extension of .plist. These files are usually XML files (although there are plaintext NeXTSTEP-style and newer binary .plist formats that can be used) and they are created using standard Cocoa libraries. Because the libraries many applications leverage include the ability to create .plist files, developers find it easy to use this format to store settings and preferences. (This is the same file format used to tell the operating system how to launch Application Bundles.)

System-wide settings are stored in the /Library/ directory or in the /System/Library/ directory, depending on purpose. (The /etc directory still exists and is used for configuration for legacy services such as Samba and SSH.)


Daemons and Services

Like any Unix-based operating system, services are provided by daemons that run in the background and are typically spawned automatically. Versions of OS X up through 10.3 used the traditional method: the kernel runs init, which launches daemons and also starts cron for periodic scheduling. In Mac OS X 10.4, Apple introduced a new framework for daemons that does away with a lot of those legacy solutions: launchd.

launchd replaces mach_init as the program launched by the kernel to bring up the system. It is PID 1 and all other services are spawned by it. Earlier methods of launching and scheduling like /etc/rc and cron jobs are deprecated in Mac OS X 10.4 and above.

Programs can be launched by launchd on demand, much like with inetd or xinetd, so daemons aren't left running unless they're actively in use. launchd can monitor network ports for incoming connections and spawn daemons when they're needed. This is done with SSH, CUPS, and Samba in OS X 10.4, among others.

launchd also replaces cron, launching programs periodically.

It uses .plist files to store information on managed services.


Networking

Mac OS X includes all of the normal networking bells and whistles that we've come to expect from modern Unix-like systems. In addition to a full TCP/IP stack and support for various other networking protocols, many standard networking services are included such as the Apache web server, SSH for remote access, Samba to allow file sharing with CIFS hosts, various services supported by xinetd, and so on. Most of the networking services bundled with the operating system are open source projects and haven't been modified any more than an average Linux distribution would modify them.

For firewall functionality, Mac OS X uses the IPFW firewall familiar to many BSD users. Basic firewall settings are available in the System Preferences program and are generally sufficient to protect the casual user, but more advanced rules can be written and enacted just as they would on FreeBSD. The firewall is disabled by default, but it can be enabled with a single buttonpress. (I would recommend that all users enable it as soon as they install Mac OS X or get a new Macintosh.)

Despite these features, most users will encounter Mac OS X's networking through two avenues: browsing the World Wide Web and checking their e-mail. OS X includes a capable web browser, Safari, which is based on a fork of the KDE Project's KHTML engine. A mail application is also bundled, fittingly named Mail, which offers standard mail client features and uses WebKit (the KHTML-based library powering Safari) for displaying mail. Both Safari and Mail are built using the Cocoa APIs discussed in Toolkits above.A variety of other choices are available in both of these areas, including Firefox, Camino (a port of the Gecko engine with a Cocoa front end), and Opera for viewing webpages, and Thunderbird and Microsoft Entourage for e-mail.


Searching

In Mac OS X 10.4, a new search API called Spotlight was introduced, and became one of the most publicized features of the release. Spotlight includes in-kernel tracking of file changes, a database of file information and metadata, an API for accessing the data, integration into the OS and various applications, and a set of utilities for searching from the command line.

Spotlight allows for “live” searches of the file system much like BFS did on BeOS and the Beagle Project aims to do on Linux. (In fact, Apple hired Dominic Giampaolo, creator of BFS, to do work on filesystems several years ago. Spotlight has been called his “baby”8.)

Most users will interact with Spotlight through the Finder or the magnifying glass icon located in the menu bar in OS X 10.4, but developers are also given access through a set of search APIs published before the operating system was released. Developers can give Spotlight information on their own file formats so it can index their metadata and add to the system's usefulness, and they can also leverage Spotlight to perform searches and further integrate their applications into the file system.

A set of command line utilities for managing Spotlight allows users to create shell scripts for data management, control the Spotlight system, or perform searches from a shell. The mdfind (metadata find) utility is used to search with Spotlight, and the mdutil utility allows you to disable/enable indexing of filesystems, flush the Spotlight index databases to disk, or empty the indexes.

More information is available in mdfind(1), mdutil(1), mdimport(1), and mdcheckschema(1).


Mac OS X at the Command Line

Although many casual users will never encounter the command line on Mac OS X, users of Linux and other Unices will probably use it heavily when interacting with the system. Apple has kept the Unix heritage of its operating system in mind and provides substantial functionality from the shell for users who are interested in using it.

Mac OS X doesn't include a process filesystem (or more advanced filesystem) mounted in /proc/, /sys/, or some other similar location. Information on processes is available through a variety of facilities including the ubiquitous ps. Configuration control can be managed using the sysctl utility, and information on the system's state can be accessed using ioreg and a variety of other utilities. (See Mac OS X Hacking Tools for a more complete list and more information.)

Man pages are included in the OS, and Apple has provided manuals of reasonable quality for their command line utilities and configuration files. Related utilities such as apropos are also included.

A full suite of BSD utilities is included with the operating system, with a few notable exceptions like GNU nano (which replaces pico in OS X 10.4). BSD ls, sed, mount and so on are included – don't assume that a utility has GNU extensions! Package managers such as fink can install the GNU utilities if they are needed on an OS X system.

A wide variety of shells can also be found on OS X. The current default is bash, although earlier versions defaulted to tcsh. Users can also select zsh and ksh if they so prefer.


For Developers

Mac OS X is a good platform for developers of applications designed for generic Unix systems as well as developers of Mac-specific software. Apple distributes a free IDE called Xcode which is generally regarded to be the best of breed IDE for the platform, and Xcode includes the GNU Compiler Collection (including GCC 4.0 in the latest releases). Scripting languages are available in force, including stalwarts like Perl and interpreters for newer languages such as Python and PHP (including mod_php for Apache). vim and emacs are included for developers wishing to use their favorite programming editors instead of resorting to Xcode or other editors.

Version control software including OS X versions of CVS and Subversion are also available – CVS is bundled with the operating system, and Subversion can be installed using packages from Subversion's project page or using a package manager.

Java is well-supported in Mac OS X, including Cocoa bindings to allow native software to be written and distributed using Java.

Software written for Mac OS X is typically written in Objective-C (an alternate object-oriented dialect of C that uses reference counting for memory management and has a Smalltalk-inspired syntax for objects and messages) when using the Cocoa libraries or C++ and C when using the Carbon libraries. Other bindings available for Cocoa, such as the Python bindings, are community-driven projects from outside of Apple and aren't supported.


Further Reading

This is only a brief overview of Mac OS X, and many other features and details pertinent to Linux users have been covered by other sources.


Questions?

Speak now, or may the inquiring process be forever backgrounded.


References

  1. Wikipedia: Mac OS X
  2. Wikipedia: NEXTSTEP
  3. Wikipedia: Apple Public Source License
  4. Apple: Overview of Mac OS X File Systems
  5. Ars Technica: Mac OS X 10.4 Tiger : Page 7
  6. Ars Technica: Mac OS X 10.4 Tiger : Page 8
  7. KernelThread: Booting Mac OS X
  8. Daring Fireball: Spotlight on Spotlight

Revisions