3

我通过终端加载了一项服务作为 launchctl load /System/Library/LaunchAgent/com.example.my.plist

现在,我需要以编程方式检测服务是否正在运行并启动服务。 http://www.opensource.apple.com/source/launchd/launchd-328/launchd/src/launch.h 上面是Apple提供的launch.h api的链接,有助于实现这一目标。

任何人都可以帮我处理它的文档吗?或者,帮助我如何使用 api 检查服务的状态并启动它。

谢谢。

4

1 回答 1

0

此 API 的大部分内容现已弃用(macOS 10.14 SDK):

/*!
 * @header
 * These interfaces were only ever documented for the purpose of allowing a
 * launchd job to obtain file descriptors associated with the sockets it
 * advertised in its launchd.plist(5). That functionality is now available in a
 * much more straightforward fashion through the {@link launch_activate_socket}
 * API.
 *
 * There are currently no replacements for other uses of the {@link launch_msg}
 * API, including submitting, removing, starting, stopping and listing jobs.
 */

该解决方案似乎使用launchctlman launchctl或此处的在线内容:https ://ss64.com/osx/launchctl.html )。可能是这样launchctl list | grep <agent label>的。

于 2018-09-05T10:34:04.007 回答