What is launchd?
Wikipedia defines launchd as “a unified, open-source service management framework for starting, stopping and managing daemons, applications, processes, and scripts. Written and designed by Dave Zarzycki at Apple, it was introduced with Mac OS X Tiger and is licensed under the Apache License.”
launchctl
launchctl 管理 OS X 的启动脚本,控制启动计算机时需要开启的服务。也可以设置定时执行特定任务的脚本,就像 Linux crontab 一样,通过加装 *.plist 文件执行相应命令。
Job Definitions
The behavior of a daemon/agent is specified in a special XML file called a property list. Depending on where it is stored it will be treated as a daemon or an agent.
Job definitions crucial for the operation of the operating system are stored below /System/Library. You should never need to create a daemon or agent in these directories. Third-Party definitions which are relevant for every user are stored below /Library. Job definitions for a specific user are stored below the respective user’s Library directory.
Type |
Location |
Run on behalf of |
User Agents |
~/Library/LaunchAgents |
Currently logged in user |
Global Agents |
/Library/LaunchAgents |
Currently logged in user |
Global Daemons |
/Library/LaunchDaemons |
root or the user specified with the key UserName |
System Agents |
/System/Library/LaunchAgents |
Currently logged in user |
System Daemons |
/System/Library/LaunchDaemons |
root or the user specified with the key UserName |
Daemons and Agents
launchd differentiates between agents and daemons. The main difference is that an agent is run on behalf of the logged in user while a daemon runs on behalf of the root user or any user you specify with the UserName key.
...
Posted by Wei
on 2020-11-21, Last Modified on 2025-04-23