launchd

On this page 8

launchd is the service management framework of macOS and the first process started in user space, running with process ID 1 and acting as the parent of every other process on a Mac. Among the core macOS fundamentals, it replaces the roles that traditional Unix systems split between init, cron, inetd and the startup scripts in a single program.

Apple introduced launchd in Mac OS X 10.4 Tiger in 2005. It reads property list configuration files, starts programs on demand when an event occurs, restarts them if they crash, and stops them when they are no longer needed. Administrators and developers interact with it through the launchctl command, while ordinary users mostly see its effects as login items and background services.

How launchd starts and supervises processes

launchd works by registering jobs first and launching programs later. When the XNU kernel finishes booting, it starts /sbin/launchd, which loads the job definitions found in system and user folders and creates the sockets, Mach ports and file watches those jobs request. The actual program usually stays stopped until a matching launch trigger arrives.

This design is called on-demand activation. A client that connects to a registered socket or Mach service does not need to know whether the server is running: launchd holds the connection, starts the program, and hands the endpoint over. The result is a faster boot, lower memory use and no fragile ordering of startup scripts, because dependencies are resolved by the communication channels themselves.

launchd also performs process supervision. It tracks the exit status of every job, applies throttling so that a crashing program is not relaunched more often than about once every 10 seconds by default, and can keep a job alive permanently when its configuration requests it. Because launchd is PID 1, a failure of launchd itself causes a kernel panic and an immediate restart.

Daemons, agents and their domains

launchd distinguishes jobs by who owns them and when they run. A daemon runs system-wide, usually as root or a dedicated service account, without any user interface. An agent runs on behalf of a logged-in user and may interact with the graphical session. The location of a job’s property list determines its type and its launchd domain.

The following table lists the standard job locations and their purpose.

FolderJob typeRuns asOwner of the file
/System/Library/LaunchDaemonsSystem daemonRoot or service accountApple, protected by SIP
/System/Library/LaunchAgentsSystem agentLogged-in userApple, protected by SIP
/Library/LaunchDaemonsThird-party daemonRoot or specified userAdministrator or installer
/Library/LaunchAgentsThird-party agent for all usersEach logged-in userAdministrator or installer
~/Library/LaunchAgentsPer-user agentThat user onlyThe user
Standard locations of launchd job definitions

Modern launchctl addresses these contexts as domain targets: system for daemons, gui/<uid> for the graphical session of a user, and user/<uid> for background work tied to a user account. Choosing the wrong domain is a frequent reason why a job loads but cannot reach the window server or a user’s keychain.

Property list keys that define a job

Every launchd job is described by a property list file, in XML or binary form, whose keys tell launchd what to run and when. Only Label is strictly required, but a useful job also names the program and at least one trigger. Apple documents the complete key set in the launchd.plist manual page.

The keys below cover most real configurations.

KeyValue typeEffect
LabelStringUnique job identifier, usually reverse DNS
ProgramArgumentsArray of stringsExecutable path and its arguments
RunAtLoadBooleanStarts the job as soon as it is loaded
KeepAliveBoolean or dictionaryRestarts the job always or under conditions
StartIntervalInteger in secondsRuns the job at a fixed interval
StartCalendarIntervalDictionaryRuns the job at calendar times, like cron
WatchPathsArray of pathsRuns the job when a file or folder changes
Sockets / MachServicesDictionaryStarts the job when a client connects
Frequently used launchd.plist keys

A missed calendar event behaves differently from cron: when a Mac is asleep at the scheduled time, launchd runs the job once after waking instead of skipping it. When the Mac is fully shut down, however, the event is not replayed.

launchd compared with other init and scheduling systems

launchd is best understood as a consolidation of several Unix tools into one event-driven supervisor. Its design later influenced systemd on Linux, which adopted socket activation and dependency-free parallel startup. The comparison below shows where the concepts overlap.

MechanismPlatformMain roleKey difference from launchd
SysV initClassic Unix, older LinuxRuns ordered startup scriptsNo on-demand start or supervision
cronUnix and LinuxTime-based schedulingSkips jobs missed during sleep
inetd / xinetdUnix and LinuxStarts servers on network connectionsNetwork sockets only
systemdModern LinuxInit, supervision, socket activationUnit files and explicit dependencies
Windows Service Control ManagerWindowsStarts and monitors servicesSeparate Task Scheduler for timing
launchd and comparable mechanisms

macOS still ships cron for compatibility, but Apple has recommended launchd for scheduled tasks for many years. XPC services inside applications are also launched and managed by launchd, which makes it the backbone of interprocess communication on Darwin.

Managing jobs with launchctl

Administrators control launchd through launchctl, which has two generations of subcommands. The legacy load and unload commands still work but are deprecated; the modern syntax since OS X 10.10 Yosemite uses bootstrap, bootout, enable, disable, kickstart and print together with a domain target.

TaskModern commandNotes
Load a daemonsudo launchctl bootstrap system /Library/LaunchDaemons/x.plistRequires root
Unload a user agentlaunchctl bootout gui/501/com.example.jobUses the job label
Restart a job nowlaunchctl kickstart -k gui/501/com.example.jobThe -k flag kills the running instance
Inspect statelaunchctl print system/com.example.jobShows triggers, PID and last exit
Prevent loadinglaunchctl disable gui/501/com.example.jobPersists across restarts
Common launchctl tasks

Since macOS 13 Ventura, applications can register helpers through the SMAppService interface, and the system notifies users about new background items in System Settings under Login Items. This gives users visibility into launchd jobs that were previously installed silently.

Security role, limitations and common mistakes

Because launchd can run any program automatically, launch agents and daemons are a classic persistence mechanism for malware. Security tools therefore monitor the LaunchAgents and LaunchDaemons folders, and System Integrity Protection prevents modification of Apple’s own jobs in the sealed system volume.

  • Wrong file ownership or permissions: daemons in /Library/LaunchDaemons must be owned by root:wheel and not writable by others, or launchd refuses to load them.
  • Programs that fork into the background: launchd expects the process to stay in the foreground; a self-daemonizing program looks like an exit and triggers restarts.
  • Missing environment: jobs do not inherit a shell PATH, so scripts should use absolute paths or set EnvironmentVariables.
  • Overly aggressive KeepAlive: an unconditional KeepAlive on a failing program wastes resources through repeated throttled restarts.
  • Duplicate labels: two property lists with the same Label conflict, and only one job is registered.

launchd also offers no explicit dependency graph, so a job that needs a network volume or another service must handle the absence itself, for example by retrying or by using a WatchPaths trigger.

Understanding it simply

launchd is the building manager of a Mac. It is the first program that wakes up after the core of the system starts, and it is in charge of every other background program that follows.

Instead of keeping every service running all day, launchd keeps a list of who should be called and when. When a request arrives, a file changes or a scheduled time comes, it starts the right program, watches it, and restarts it if it stops unexpectedly. The key idea is starting work only when it is needed, which saves time and memory.

Applied in practice

A systems administrator at a design studio manages 40 Macs that must copy finished project files to a network server every night. Instead of a cron entry, the administrator deploys a single launchd daemon to /Library/LaunchDaemons with a Label of com.studio.nightlysync, a ProgramArguments entry pointing to a sync script, and a StartCalendarInterval of 23:30.

Some designers close their laptops before leaving, so those Macs are asleep at 23:30. Because launchd runs a missed calendar job after wake, every laptop completes its backup the next morning within minutes of opening the lid. The administrator checks the result remotely with launchctl print, which shows the last exit code of 0 on each machine, and fixes one failing Mac whose script lacked an absolute path to rsync.