Launch daemon

Also known as: LaunchDaemons

On this page 7

A launch daemon is a system-wide background job in macOS that the launchd service manager starts and supervises, usually as root, independently of any user being logged in. Each daemon is described by a property list file stored in /Library/LaunchDaemons (third-party jobs) or /System/Library/LaunchDaemons (Apple jobs), often referred to simply as LaunchDaemons.

In Terminal and scripting work on macOS, launch daemons replace older Unix mechanisms such as cron, init scripts and inetd. Administrators use them to run maintenance scripts, network services and agents of management tools, while the neighboring concept of a launch agent covers jobs that run inside a user session.

How launchd loads and runs a launch daemon

A launch daemon runs because launchd, process ID 1, reads its property list and registers the job in the system domain. At boot, launchd scans the daemon directories, validates each file and decides whether to start the program immediately or wait for a trigger such as a timer, a socket connection or a file change.

The job is identified by its Label key, a unique reverse-DNS string such as com.example.backup. The program itself is named in Program or ProgramArguments, and launchd starts it directly without a shell, so shell features such as pipes, variable expansion and the ~ shortcut do not work unless the job explicitly calls /bin/zsh -c. This no-shell execution is the most common surprise for script authors.

Once running, the process is supervised rather than forgotten. Launchd captures its exit status, can restart it according to the KeepAlive rules and throttles jobs that exit too quickly. A daemon must therefore stay in the foreground: a program that forks into the background in the classic Unix style appears to launchd as a job that has already exited.

The lifecycle can be summarized in the following stages, from the file on disk to a running process.

StageWhat happensTypical command or event
InstallationPlist copied to the daemon directory, owned by root:wheelsudo cp or an installer package
BootstrapJob registered in the system domainlaunchctl bootstrap system <plist> or reboot
TriggerLaunch condition metBoot, timer, socket, path change
ExecutionProgram runs as root or the UserName accountlaunchd spawns the process
SupervisionExit status recorded, restart evaluatedKeepAlive and ThrottleInterval rules
RemovalJob unregistered and stoppedlaunchctl bootout system/<label>
Lifecycle of a launch daemon

Key property list keys for LaunchDaemons

The behavior of a launch daemon is defined entirely by keys in its plist, which can be written in XML or edited with tools such as plutil and defaults. A small set of keys covers almost every practical job, and the table below lists the ones administrators use most often.

KeyPurposeExample value
LabelUnique job identifiercom.example.cleanup
ProgramArgumentsExecutable and its arguments as an array/usr/local/bin/cleanup.sh, –quiet
RunAtLoadStart once when the job is loadedtrue
StartIntervalRun every N seconds3600
StartCalendarIntervalRun at calendar times, cron styleHour 2, Minute 30
KeepAliveRestart conditions after exittrue or a dictionary of conditions
UserNameAccount the daemon runs as_www or a service account
StandardOutPathFile that receives standard output/var/log/cleanup.log
WatchPathsStart when a path changes/Library/Preferences/example.plist
Frequently used launchd keys

StartCalendarInterval differs from cron in one useful way: if the Mac was asleep at the scheduled time, launchd runs the missed job once after wake. If the Mac was powered off, the run is skipped. StartInterval counts seconds while the system is awake and does not catch up after sleep in the same way.

Launch daemon versus launch agent and other job types

A launch daemon differs from a launch agent mainly in domain and privileges: the daemon belongs to the system and has no access to the graphical session, while an agent runs per user and can show windows, use the keychain of that user and interact with the menu bar.

MechanismRuns asNeeds a logged-in userTypical use
Launch daemonRoot or a named accountNoSystem services, management agents, scheduled maintenance
Launch agentThe logged-in userYesMenu bar helpers, user sync tools
Login itemsThe logged-in userYesApps opened at login
cronCrontab ownerNoLegacy schedules, still supported but discouraged
SMAppService daemonRoot, approved by the userNoDaemons bundled inside a modern app
Comparison of background job mechanisms on macOS

Since macOS 13 Ventura, apps can register helpers through the SMAppService framework, and every third-party daemon appears in System Settings under Login Items and Extensions, in the section that allows background activity. Users can switch such items off there, which means an administrator relying on a daemon should manage that setting with an MDM profile.

Creating and managing a launch daemon with launchctl

Managing a launch daemon means writing a valid plist, setting strict ownership and permissions, and loading it with launchctl. Launchd refuses to load a daemon plist that is writable by group or others or not owned by root, because such a file would let any user run code as root.

  1. Write the plist to /Library/LaunchDaemons/com.example.cleanup.plist and validate it with plutil -lint.
  2. Set owner root:wheel and mode 644 with chown and chmod.
  3. Load it with sudo launchctl bootstrap system /Library/LaunchDaemons/com.example.cleanup.plist.
  4. Inspect the job with sudo launchctl print system/com.example.cleanup, which shows state, last exit code and run count.
  5. Force a run for testing with sudo launchctl kickstart -k system/com.example.cleanup.

The older subcommands load and unload still work but are deprecated in favor of bootstrap and bootout, which report errors more clearly. The output of launchctl print is the fastest way to see why a job does not run, because it shows the last exit code and the reason the job is waiting.

Common mistakes and security risks

Most failures of a launch daemon come from environment assumptions. Launchd starts the job with a minimal PATH, no user home directory and no interactive shell profile, so a script that works in Terminal can fail silently when launchd runs it.

SymptomLikely causeFix
Job never startsWrong ownership or invalid plistSet root:wheel 644, run plutil -lint
Command not found in logsMinimal PATH under launchdUse absolute paths or set EnvironmentVariables
Job restarts every 10 secondsKeepAlive with an immediately exiting programRemove KeepAlive or keep the process in the foreground
Permission denied on user foldersPrivacy protections block rootGrant Full Disk Access through a PPPC profile
Job disabled after an updateUser switched off background itemManage background items with MDM
Symptoms, causes and fixes

From a security perspective, launch daemons are a classic persistence mechanism for malware, because they survive reboots and run with full root privileges. Defenders should review /Library/LaunchDaemons regularly, verify that every referenced binary is signed and notarized, and treat an unknown daemon as a strong indicator of compromise. Scripts referenced by a daemon must also be root-owned, otherwise an ordinary user can replace them and gain root.

In everyday language

A launch daemon is like a night-shift worker built into the Mac. Nobody has to be signed in for it to do its job. When the computer starts, the system reads a small instruction card for each worker, which says what program to run, when to run it and what to do if it stops.

Some workers run all the time, such as a service that answers network requests. Others wake up on a schedule, for example every night at two in the morning to clean old files. The key point is that a launch daemon works for the whole computer, not for one person, and it has powerful permissions, so only trusted programs should ever be set up this way.

Seen in the real world

An IT administrator at an architecture firm manages 60 Macs that store large project files locally. To keep disks from filling up, the administrator writes a short zsh script that deletes render caches older than 14 days and logs the amount of space it recovered.

The script is placed in /usr/local/libexec, owned by root, and a plist named com.firm.cachecleanup in /Library/LaunchDaemons runs it with StartCalendarInterval at 03:15 every day and writes output to /var/log/cachecleanup.log. Because the Macs often sleep overnight, launchd runs the missed job right after wake. The MDM also deploys a profile that approves the background item and grants Full Disk Access to the script interpreter. After one month, average free space rises by about 40 GB per Mac, and support tickets about full disks stop.