How to find and kill a port

Photo by Markus Winkler on Unsplash

This is a simple approach which we need on daily basis which is find and kill a port.

Following are the steps to find and kill the port.

  1. You should find the process id which is known as pid using the port as follows.

Following is a sample output for sudo lsof -i :3000

2. Then get the pid which is bolded in the above example and kill it as follows. kill [option] <pid>

or you can simply kill it without give time to cleanup.

Okay what if I don’t know what is the port id? Then list all the ports and find it as follows.

Important: If you don’t know the port but you know process name or anything you can simply use grep using pipe and filter out as follow.

Above will filter processes with mysqld as follows.

Hope this will be helpful.

If you have found this helpful please hit that 👏 and share it on social media :).

Technical Writer | Tech Enthusiast | Open source contributor