How to view status of service (e.g. whether it's running) in a format similar to Linux `systemctl` using macOS `launchctl`? How to view status of service (e.g. whether it's running) in a format similar to Linux systemctl using macOS launchctl?


I want to view the status of a service in macOS using launchctl in a format similar to Linux systemctl, e.g: systemctl status sshd.service

I attempt this using the below launchctl list commands. It's not obvious whether Apache is running, and I've read that - in the first column in the latter command should mean that the service isn't running.

Any ideas?

Nicolass-MacBook-Pro:Documents nlykkei$ sudo launchctl list org.apache.httpd
{
        "LimitLoadToSessionType" = "System";
        "Label" = "org.apache.httpd";
        "TimeOut" = 30;
        "OnDemand" = false;
        "LastExitStatus" = 0;
        "Program" = "/usr/sbin/httpd-wrapper";
        "ProgramArguments" = (
                "/usr/sbin/httpd-wrapper";
                "-D";
                "FOREGROUND";
        );
};
Nicolass-MacBook-Pro:Documents nlykkei$ sudo launchctl list | grep apache
-       0       org.apache.httpd
I want to view the status of a service in macOS using launchctl


Hi, 

to view the status, use print: launchctl print system/org.apache.httpd

Syntax is:  launchctl print &lt;domain&gt;/&lt;item&gt;

Domain can be:

 `system/&lt;service&gt;`
 `user/&lt;UID&gt;`
 `pid/&lt;PID&gt;`
 `session/&lt;asid&gt;`




Various combinations and examples below:

Use: launchctl list to list all services. Simple listing of known services, not detailed.

Sample output:

$ launchctl list

PID Status  Label
659 0   com.apple.trustd.agent
-   0   com.apple.MailServiceAgent
-   0   com.apple.mdworker.mail
99270   0   com.apple.mdworker.shared.0E000000-0000-0000-0000-000000000000
-   0   com.apple.mdworker.shared.04000000-0000-0000-0000-000000000000
-   0   com.apple.appkit.xpc.ColorSampler
652 0   com.apple.cfprefsd.xpc.agent
-   0   com.apple.coreimportd
770 0   com.apple.TrustedPeersHelper
-   0   com.apple.SafariHistoryServiceAgent
1236    0   com.apple.progressd
3111    0   com.apple.cloudphotod
758 0   com.apple.Finder
693 0   com.apple.homed
-   78  com.ajsoft.a.mail




The first column is the process PID
The second column is a return code
The 3rd column is process label


Itens with - on the first column are NOT running

Itens with - and not 0 on the second column were executed at least once, but are now either sleeping or stopped, example: -    78  com.ajsoft.a.mail




Detailed list of all services under the system domain: [all, including enabled and disabled ones]


sudo launchctl print system/ 

To get detailed list only of the DISABLED System services:


sudo launchctl print-disabled system/ 

To get ALL information about a specific system service


launchctl print system/com.vix.cron 



sample output:

$ launchctl print system/com.vix.cron

com.vix.cron = {
    active count = 0
    copy count = 0
    one shot = 0
    path = /System/Library/LaunchDaemons/com.vix.cron.plist
    state = waiting

    program = /usr/sbin/cron
    arguments = {
        /usr/sbin/cron
    }

    default environment = {
        PATH =&gt; /usr/bin:/bin:/usr/sbin:/sbin
    }

    environment = {
        XPC_SERVICE_NAME =&gt; com.vix.cron
    }

    domain = com.apple.xpc.launchd.domain.system
    domain umask = 22
    minimum runtime = 10
    exit timeout = 5
    runs = 0
    successive crashes = 0
    last exit code = (never exited)



To print all services under the domain of the user with UID 501


launchctl print user/501

Get all information using the service or application PID (returned by the command 'launchctl list`) 


launchctl print pid/758 



sample output:

com.apple.xpc.launchd.domain.pid.Finder.758 = {
    type = process
    handle = 758
    active count = 91
    on-demand count = 1
    service count = 90
    active service count = 2
    activity ratio = 0.02
    originator = /System/Library/CoreServices/Finder.app
    creator = Finder.758
    creator euid = 503
    uniqueid = 758
    external activation count = 0
    security context = {
        uid = 503
        asid = 100008
    }

    bringup time = 20 ms
    death port = 0x52a63

    in-progress bootstraps = 0
    pended requests = 0
    pending requests = {
    }
    subdomains = {
    }
    pending attachments = {
    }

    environment = {
        PATH =&gt; /usr/bin:/bin:/usr/sbin:/sbin
        SSH_AUTH_SOCK =&gt; /private/tmp/com.apple.launchd.Me9t1KNNjL/Listeners
        TMPDIR =&gt; /var/folders/km/w6p6dvwx6qb16nzxdwy5m5080000gq/T/
    }

    services = {
               0      -     com.apple.amp.devicesui
               0      -     com.apple.security.pboxd
               0      -     com.apple.coremedia.videodecoder
               0      -     com.apple.SafariServices
               0      -     com.apple.MediaLibraryService
               0      -     com.apple.coreservices.SharePointManagementService
               0      -     com.apple.managedclient.pds.Exchange
               0      -     com.apple.SystemExtensionsMDM
               0      -     com.apple.LookupViewService



To get information using the session id


launchctl print session/100008 



sample output:

com.apple.xpc.launchd.domain.session.100008 = {
    type = session
    handle = 100008
    active count = 1
    on-demand count = 0
    creator = launchctl.42668
    creator euid = 0
    external activation count = 0
    security context = {
        uid unset
        asid = 100008
    }

    death port = 0x0




Useful commands:


This command installs/add a service:


launchctl load /Library/LaunchDaemons/com.ServiceExample.plist 

This command enable a service to auto run after installed: 


launchctl enable system/com.ServiceExample

This command disable a installed service from auto-running: 


launchctl disable system/com.ServiceExample

This command start a service: 


launchctl start system/com.ServiceExample

This command stop a service: 


launchctl stop system/com.ServiceExample

This command remove a service:


launchctl unload /Library/LaunchDaemons/com.ServiceExample.plist 

This command force execution of a recent loaded service: 


launchctl kickstart -p /Library/LaunchDaemons/com.ServiceExample.plist

This command Stops and Disable a running service


launchctl bootout system/com.ServiceExample



You can change the above 'system domain' for a 'user domain' process.


Install/add means: include the service on the listing of services that the system knows about. (so you can start and stop it)
remove means: remove the service from the system listing of known services. (it will not be listed anymore if you execute launchctl list)


No files are deleted by removing the service, you just remove its .plist reference from the list of services. Once removed you cannot start/stop it. And it will not show on the launchctl list. Unless you add it again with the load parameter.