【问题标题】:"launchctl start" not working in a launch daemon process“launchctl start”在启动守护进程中不起作用
【发布时间】:2011-10-15 15:10:13
【问题描述】:

我有一个守护进程,在 Mac 上使用 launchd 设置。守护进程以 root 身份运行。以下行不会启动我的 UI 应用程序 -

system("launchctl start com.project.myproj");

但是如果我去终端运行相同的命令 -> launchctl start com.project.myproj。它启动我的应用程序。我的问题是我做错了什么还是系统行为不正确?

【问题讨论】:

    标签: cocoa launchd


    【解决方案1】:

    问题是系统启动的启动守护进程无法访问 Aqua,因此您的守护进程无法访问桌面环境。

    Apple 的Technical Note TN2083: Daemons and Agents 描述了其中的一些内容。 (见this section on launchd agents。)

    有人问了similar question about accessing the Aqua environment from an SSH connection

    我猜你需要重新设计你的应用程序:

    1. 创建一个在每个用户的 Aqua 会话中运行的启动代理。
    2. 让代理连接到您的根守护程序,或让根守护程序查找启动代理的实例。
    3. 当根守护程序发出信号时,让启动代理启动应用程序的图形部分。

    【讨论】:

      最近更新 更多