How to check the status (start / stop) of a process / daemon on a Mac?

On Linux, we have the command "/etc/init.d/process_name status", this will make it possible to start or stop the process / daemon.

Example for Ubuntu:

root @ Ubu91032b-Bassu: ~ # / etc / init.d / ssh status

  • sshd works

root @ Ubu91032b-Bassu: ~ #

My question is: is there any command (like above) on the Mac to check the status of the daemon / process?

+6
macos
source share
4 answers

The documented β€œmodern” way, I suppose, would be to ask launchctl , the control tool for launchd , which Apple uses to replace init , inetd , crond and a bit more:

 ~> sudo launchctl list | grep ssh 41032 - 0x100502860.anonymous.sshd - 0 com.openssh.sshd 
+16
source share

Yes, there is a way to do this in the launchd / launchctl paradigm:

 sudo launchctl bslist 

will give you the output of all loaded startup processes with

A for active. he works

I for inactive. He must not run. It should not work on its own, and I hope you will notice how my tone is not final. But this should not surprise you, I have to say.

D on request. It doesn’t work now, but it may be, since it could start at any time.

Also, if you want to create a tree structure so you can see which process spawned what:

 sudo launchctl bstree 

You'll get

  A com.apple.windowserver.active D com.apple.DirectoryService.localonly com.apple.metadata.mds[46].subset.109 (Explicit Subset)/ D com.apple.Spotlight.ImporterWorker.89 D com.apple.Spotlight.ImporterWorker.i386.89 A com.apple.Spotlight.ImporterWorker.501 D com.apple.Spotlight.SyncScanWorker 

This is a tree of processes and their states.

If you are like me, you will want to use some things from here , because you can find some features when you look,

+4
source share

For this purpose you can use the service command:

 bash-3.2$ service usage: service service command service --list service --test-if-configured-on service service --test-if-available service bash-3.2$ service --test-if-configured-on ssh && echo "SSH running" SSH running 

This command has been removed in OS X later version 10.6 (Snow Leopard). Use launchctl .

+1
source share

To switch remote login use "System Preferences" => "Sharing" => "Remote Login" through the user interface to enable SSH (see http://support.apple.com/kb/PH13759 for more).

Remote login via SSH is disabled (not checked):

 $ sudo launchctl list com.openssh.sshd launchctl list returned unknown response 

Remote login via SSH is enabled (verified):

 $ sudo launchctl list com.openssh.sshd { "Label" = "com.openssh.sshd"; "LimitLoadToSessionType" = "System"; "OnDemand" = true; "LastExitStatus" = 0; "TimeOut" = 30; "Program" = "/usr/libexec/sshd-keygen-wrapper"; "StandardErrorPath" = "/dev/null"; "ProgramArguments" = ( "/usr/sbin/sshd"; "-i"; ); "inetdCompatibility" = { "Wait" = false; }; "Sockets" = { "Listeners" = ( file-descriptor-object; file-descriptor-object; ); }; }; 
+1
source share