tags:

views:

28

answers:

2

In Linux, we have the command "/etc/init.d/process_name status", this will give whether the process/daemon is running or stopped.

For Example In Ubuntu:

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

  • sshd is running

root@Ubu91032b-Bassu:~#

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

A: 

You can use the service shell command for that purpose:

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
sakra
A: 

The documented “modern” way would, I believe, be to ask launchctl, the controlling 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
Christopher Creutzig
But, in launchctl command we cant get the status of a daemon. It will show the PID of the daemon, if it is running else it will just show the "-".
So you get information on whether the daemon is running, and the second entry is supposed to give you some form of “status”, it certainly is 1 for two startup launchd things on my machine that are broken. What more of a status are you asking for? And besides, you can also get information such as the last exit code, try `sudo launchctl list com.apple.fseventsd` or something like that.
Christopher Creutzig