Wednesday, 21 March 2012

Restarting and managing services on Mac OS X

Method 1

Searching running processes to get he PID, then killing it (The service will automatically restart).

Code Snippet
  1. sudo ps -A | grep -i ssh
End of Code Snippet

23450 ?? S 0:00.12 /usr/sbin/sshd -i
23455 ?? S 0:00.03 /usr/sbin/sshd -i
23649 p8 S+ 0:00.00 grep -i ssh

Now use 'kill' on the PID...
Code Snippet
  1. sudo kill 23450
End of Code Snippet

Method 2

launchd is a unified, open-source service management framework for starting, stopping and managing daemons, applications, processes, and scripts. Written and designed by Dave Zarzycki at Apple, it was introduced with Mac OS X Tiger and is licensed under the Apache License.

We will be using launchctl, a subset of this framework to manage services...

List all services
Code Snippet
  1. launchctl list
End of Code Snippet

We can then use this list to identify the names of our services.

Here's an example with SSH...

Stopping a service
Code Snippet
  1. launchctl stop com.openssh.sshd
End of Code Snippet

Starting a service
Code Snippet
  1. launchctl start com.openssh.sshd
End of Code Snippet

1 comment:

mahasiswa teladan said...

hi...Im student from Informatics engineering nice article,
thanks for sharing :)