我有一个启动守护进程和一个启动代理。我想在启动守护进程启动后立即运行我的启动代理(无需重新启动 macOS。)
我正在考虑通过调用(从我以 root 身份运行的启动守护程序)来做到这一点:
//501 in the hardcoded example below is the logged in user ID
//
int r = system("/bin/launchctl bootstrap gui/501 /Library/LaunchAgents/com.example.MyLaunchAgent.plist");
但是
system
返回 512 并且我的启动代理没有启动。
我做错了什么?
附言。我还尝试使用
launchctl
以更详细的代码示例开始 execl
并得到类似的结果。
PS2。请注意,如果我从 root 下的终端运行我为
system
调用显示的命令行,它会很好地启动我的启动代理。