Troubleshooting Ports
From Mac OS X Server FAQ
Only one process at a time may 'bind' to a given port on a given IP address. In the event that an application tries to bind a port that is already bound, find out which process has the port open. Refer to Network Service Ports for information on how to diagnose what port the service is using.
It may be necessary to kill off whatever has the port open - perhaps a duplicate instance of a service. In order to do this, you need to find the Process ID (PID) of the offending process. Once you know the name of the service, you can use ps or lsof to find the Process ID. With lsof, the process ID is in the second column of output. In the example lsof output below, the process ID of the smbd process is 456.
smbd 456 root 13u IPv4 0x02b274c8 0t0 TCP *:445 (LISTEN) smbd 456 root 14u IPv4 0x02b2777c 0t0 TCP *:139 (LISTEN)
If you know the name of the service, but not the process ID, try searching for it with Activity Monitor, or via ssh using ps if you don't have physical accesss to the server. Use the form ps auxwww | grep name, where 'name' is the process name you are searching for. Alternatively, execute just ps auxwww to see a list of all processes.
Example output is shown below for ps auxwww | grep smbd. The process ID is shown in the first colume; in this example, 449.
449 0.0 0.1 30332 476 ?? Ss Fri02PM 1:18.57 /usr/sbin/smbd -D
Once you have the process ID, it is now possible to send the process a signal that tells it to go away. Generally it is wise never to kill a process without first trying to stop it the normal way. Be advised that there is the potential for data loss related to that processes function.
sudo kill PID where PID is the Process ID. This sends a 'nice' signal, called TERM. If this does not work, you may need to forcibly terminate the process with kill -9 PID which sends a KILL signal, and is pretty much the most severe way to terminat a process short of a reboot.
After all this, verify that the port is no longer in use with lsof or netstat, and then attempt to restart the service.
