3

I have a service loaded via terminal as launchctl load /System/Library/LaunchAgent/com.example.my.plist

Now, I need to programmatically detect if the service is running or not and start the service. http://www.opensource.apple.com/source/launchd/launchd-328/launchd/src/launch.h Above is the link to launch.h api provided by Apple that helps to achieve this.

Can anyone help me with its documentation? or, help me how to use the api to check the status of a service and to launch the same.

Thanks.

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
VS7
  • 133
  • 2
  • 6

1 Answers1

0

Most of this API is now deprecated (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.
 */

The solution seems the use of launchctl (man launchctl or something online here: https://ss64.com/osx/launchctl.html). Something like launchctl list | grep <agent label> maybe.

Liviu
  • 1,859
  • 2
  • 22
  • 48