Kill sockets

From LQWiki
(Redirected from Kill Sockets)
Jump to: navigation, search

Sometimes in your System Administrator's life, you have services running that block networking ports. This can result in a program not starting and giving you the error message

socket already in use

An example is a process listening on port 80. It will make it impossible to start a typical web server because port 80 is the default web server (http or www) port. In order to start a web server, you will have to kill that other process. A socket is the combination of an IP address and a port number.

To kill a process blocking a socket first find the socket you are interested:

netstat -avp

"a" for "all," "v" for "verbose," and then "p" for "process" (show process #). For example, you could find a line

tcp   0   0 *:www   *:*   LISTEN   6670/apache2

This means that the process with the id 6670 listens on the www-port.

cat /etc/services | grep 

tells you that the www-port is port 80:

www   80/tcp   http   # WorldWideWeb HTTP

Then kill the respective process:

kill -9 6670