Kill a process running a particular port

Spread the love

Sometimes, when I vagrant up my dev environment, the below warning appears.

Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 9200 is already in use on the host machine.

So what we need to do is to list any process listening to the port 9200. Type in your command line:

lsof -i:9200

It will return something like this:

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
644 Smith IPv6 0x106de0781c6c7bd3 0t0 TCP [fe80:1::1]:wap-wsp (LISTEN)
644 Smith IPv6 0x106de0781c6c7673 0t0 TCP localhost:wap-wsp (LISTEN)

Finally kill the process with its PID:

kill -9 644