在Mac系统中,launchd进程类似于unix/liunx系统的init进程,充当系统initial的角色,同样类似于Linux系统init脚本,launchd加载读取plist文件启动daemon,实现操作系统的基本服务结构,在daemon驻守的基础上再依据用户的操作触发dependency进程。
launchd -> daemon/agent -> dependency
在Mac系统的语境里,传统的驻守进程又分为了两类:Daemon和Agent。
-
其中Daemon是系统级别的驻留进程,默认以root身份启动执行;Agent是用户级别的驻留进程,默认以系统用户身份启动执行。
-
此外也在plist文件可以通过
UserName
字段定义启动执行的identity,一般用来实现系统级别的进程以特定用户的身份执行。
注意:所有plist文件的owner都是root,也即是launchd读取加载plist文件,在以相应的identity执行命令触发进程。
/Library/LaunchDaemons/com.xyz.tt.uecontrol.hostcontroller
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.xyz.tt.uecontrol.hostcontroller</string>
<key>UserName</key>
<string>xyz</string>
<key>ProgramArguments</key>
<array>
<string>/Users/xyz/documents/uec/uecontrol-CXC_173_6456-R38A02/hostcontroller.sh</string>
</array>
<key>KeepAlive</key>
<true/>
</dict>