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?
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
To toggle remote login use the "System Preferences" => "Sharing" => "Remote Login" via the user interface to enable SSH (see http://support.apple.com/kb/PH13759 for more).
Remote Login via SSH Disabled (Unchecked):
$ sudo launchctl list com.openssh.sshd
launchctl list returned unknown response
Remote Login via SSH Enabled (Checked):
$ 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;
);
};
};
Yes there is a way to do this within the launchd/launchctl paradigm:
sudo launchctl bslist
will give you output of all loaded launchd processes, with
A for active. It's running
I for inactive. It's not supposed to run. It should not run on it's own, and I hope you notice how my tone is not definitive. But it's not supposed to surprise you, I should mean off.
D for on demand. Not running now, but could be, since it could have started at any time.
Also, if you want a treelike structure, so you can see which process fathered 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
Which is a tree of the processes and their states.
If you are anything like me, you'll be wanting to use some stuff from here because you might find some peculiar things when you look.
精彩评论