Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

As a new comer from Windows OS, I wonder how to start/stop/restart a service on Mac OS X Snow Leopard 10.6.8 ?(it's straight forward on Windows using its Task Manager). I tried Activity Monitor, but it only kills processes, it does not start them. I tried the command: launchctl stop *servicename* and then the command launchctl start *servicename* after I hit return on keyboard after each command the terminal does not show any message so it must be successfull, but when I check out the result in Activity Monitor, it sounds that this command is useless because it has no effect on that process in Activity Monitor.

p.s. I'm sure I typed the right name of the process, I grabbed the name from the list using the command : launchctl list

EDIT: (ps auxwww command output lines)

line1:

zend 204 0.0 0.1 602396 2684 ?? Ss 10:53AM 0:00.72 /usr/local/zend/gui/lighttpd/sbin/lighttpd -m /usr/local/zend/gui/lighttpd/lib -f /usr/local/zend/gui/lighttpd/etc/lighttpd.conf -D

line2:

root 202 0.0 0.0 623124 756 ?? Ss 10:53AM 0:00.00 /usr/local/zend/bin/watchdog -c /usr/local/zend/etc/watchdog-lighttpd.ini -u zend -g zend -s lighttpd
share|improve this question

2 Answers 2

up vote 1 down vote accepted

It is strange to see the questions between "windows migrated" and "default mac" users. :) Windows migrated users usually want "somewhat tweak" the system. Default Mac users - simply "using it".

I'm using MAC much years, and never needed to use the launchctl command. If mean never, mean in normal usage, of course sometimes needed use it when installing somethings from the macports - for onetime load of startup files or so.

I'm wondering, why you need start/stop/restart services with launchctl? Asking because if you not an experienced OS X users you probably will screw the system "harmony" :). So, in this case - IMHO - better to ask the specific problem, so ask how to start/stop the specific service.


As the answer - check first System preferences. Most common services are in the "Sharing" pane" - like web-server, sshd, CD sharing and so on...

Some third party dmg files with GNU stuff comes with own preference pane too. For example, you can install precompiled MYSQL server with a preference pane, what allow you start-restart the server.

If you don't find the wanted service in prefs, be more precise. What service you need start/stop? The "launchctl" command works as needed to work, ActivityMonitor too. You ofc can use "ps axuwww" or "top" commands from the Terminal too.

Remember, your now in the UNIX world, so nearly anything can be done from the command-line, but usually thats mean really much learning.. ;)


EDIT:

try:

sudo kill -1 204
              ^-process number

from the terminal, or simply kill the daemon from the ActivityMonitor. The watchdog should restart it.

Have you any lighthttpd file in the /Library/LaunchDaemons/*? So, any output form the command:

ls /Library/LaunchDaemons | grep -i light

if yes, you can use the:

sudo launchctl unload /Library/LaunchDaemons/filename.plist
sudo launchctl load /Library/LaunchDaemons/filename.plist

command for stop/start.

share|improve this answer
    
I liked your quote about Mac vs. Windows migrated users :)& thank you so much for your thorough explanation, however, I've added a PHP extension called: "mysqli.so" to the ini file, and for this to take effect, the service named "lighttpd" must be restarted, and there is no visual interface to do that by a simple click, so I opened terminal and tried the command launcctl but as I told it has no effect on the service, I've tried your command "ps auxwww", it lists complete info about running processes, I've grabbed two lines from this command output that concerns ... to be continued next comment –  unprecedented Jul 18 '11 at 10:01
    
that concerns my process "lighttpd": line1: zend 204 0.0 0.1 602396 2684 ?? Ss 10:53AM 0:00.72 /usr/local/zend/gui/lighttpd/sbin/lighttpd -m /usr/local/zend/gui/lighttpd/lib -f /usr/local/zend/gui/lighttpd/etc/lighttpd.conf -D line2: root 202 0.0 0.0 623124 756 ?? Ss 10:53AM 0:00.00 /usr/local/zend/bin/watchdog -c /usr/local/zend/etc/watchdog-lighttpd.ini -u zend -g zend -s lighttpd believe it or not, I restarted my machine to get this service restarted !! how can I restart it from terminal or from anywhere else ? p.s.: it does not exist in SHARING. –  unprecedented Jul 18 '11 at 10:02
    
uh, can you edit your question to insert an more readable lines? Will try figure them out anyway, but should help a bit. :) –  jm666 Jul 18 '11 at 10:09
    
I'm sorry for misspelling the name: I meant "process" not "service" .. forgive me ... edited the main subject –  unprecedented Jul 18 '11 at 10:09
1  
kill -1 send the SIGHUP message to the process. The process simple got the SIGHUP message. The SIGHUP should instruct the lightppd deamon to re-read the config file. If you want really kill the process need to use "kill PID" (or kill -15 PID) or "kill -9 PID". (man kill - manual for the kill command) –  jm666 Jul 18 '11 at 10:48

I'm using MAC much years, and never needed to use the launchctl command. If mean never, mean in normal usage, of course sometimes needed use it when installing somethings from the macports - for onetime load of startup files or so.

I'm wondering, why you need start/stop/restart services with launchctl? Asking because if you not an experienced OS X users you probably will screw the system "harmony" :). So, in this case - IMHO - better to ask the specific problem, so ask how to start/stop the specific service.

I don't see a problem with asking the wider question as to how services are started and stopped if it enables the OP to better understand the underlying mechanics of the system.

As to why you would want to do this, one good reason would be to remotely kill errant processes on remote machines via Apple Remote Desktop. I do this frequently for our network users at school and it can save a lot of leg work (as well as avoiding entering repetitive terminal commands).

ARD users will want to kill processes by name rather than by PID as the process ID isn't necessarily the same each time the process is initiated...

sudo killall coreaudiod

...would be a useful command for ARD users as it's repeatable regardless of PID, whereas...

sudo kill -1 211

...would very likely only work to kill coreaudiod on the occasion that its PID was actually 211, and definitely wouldn't be an ARD command worth saving for future use. This may seem obvious to "advanced" users but unfamiliar users may not realise the difference.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.