我通过终端加载了服务 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检查服务的状态并启动它。
感谢。
答案 0 :(得分: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.
*/
该解决方案似乎使用了launchctl
(man launchctl
或此处的在线内容:https://ss64.com/osx/launchctl.html)。像launchctl list | grep <agent label>
之类的东西。