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.
| Stage | What happens | Typical command or event |
|---|---|---|
| Installation | Plist copied to the daemon directory, owned by root:wheel | sudo cp or an installer package |
| Bootstrap | Job registered in the system domain | launchctl bootstrap system <plist> or reboot |
| Trigger | Launch condition met | Boot, timer, socket, path change |
| Execution | Program runs as root or the UserName account | launchd spawns the process |
| Supervision | Exit status recorded, restart evaluated | KeepAlive and ThrottleInterval rules |
| Removal | Job unregistered and stopped | launchctl bootout system/<label> |
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.
| Key | Purpose | Example value |
|---|---|---|
| Label | Unique job identifier | com.example.cleanup |
| ProgramArguments | Executable and its arguments as an array | /usr/local/bin/cleanup.sh, –quiet |
| RunAtLoad | Start once when the job is loaded | true |
| StartInterval | Run every N seconds | 3600 |
| StartCalendarInterval | Run at calendar times, cron style | Hour 2, Minute 30 |
| KeepAlive | Restart conditions after exit | true or a dictionary of conditions |
| UserName | Account the daemon runs as | _www or a service account |
| StandardOutPath | File that receives standard output | /var/log/cleanup.log |
| WatchPaths | Start when a path changes | /Library/Preferences/example.plist |
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.
| Mechanism | Runs as | Needs a logged-in user | Typical use |
|---|---|---|---|
| Launch daemon | Root or a named account | No | System services, management agents, scheduled maintenance |
| Launch agent | The logged-in user | Yes | Menu bar helpers, user sync tools |
| Login items | The logged-in user | Yes | Apps opened at login |
| cron | Crontab owner | No | Legacy schedules, still supported but discouraged |
| SMAppService daemon | Root, approved by the user | No | Daemons bundled inside a modern app |
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.
- Write the plist to
/Library/LaunchDaemons/com.example.cleanup.plistand validate it withplutil -lint. - Set owner root:wheel and mode 644 with
chownandchmod. - Load it with
sudo launchctl bootstrap system /Library/LaunchDaemons/com.example.cleanup.plist. - Inspect the job with
sudo launchctl print system/com.example.cleanup, which shows state, last exit code and run count. - 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.
| Symptom | Likely cause | Fix |
|---|---|---|
| Job never starts | Wrong ownership or invalid plist | Set root:wheel 644, run plutil -lint |
| Command not found in logs | Minimal PATH under launchd | Use absolute paths or set EnvironmentVariables |
| Job restarts every 10 seconds | KeepAlive with an immediately exiting program | Remove KeepAlive or keep the process in the foreground |
| Permission denied on user folders | Privacy protections block root | Grant Full Disk Access through a PPPC profile |
| Job disabled after an update | User switched off background item | Manage background items with MDM |
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.