Ports are used by applications to send and receive data from and to their servers. Every application uses a specific set of ports to communicate and these ports are either automatically or manually opened when the application is installed. In this article, we will discuss the methods to terminate a process related to a port. Since all applications use a specific port, we can ask the operating system to terminate the process that is using a specific port.
How to Kill Process on Port?
Applications that are communicating on a specific port can easily be terminated by instructing the computer to do so. This process, however, differs on operating systems and requires administrative privileges. Also, make sure that there isn’t any other application that is using the port. Below the method to kill a process from its port number is listed below, since the method differs on operating systems, we have listed the methods for some of the most popular ones.
Kill Process on Port in Mac and Linux
- Open the terminal and make sure you are signed in as the root user.
- List the processes that are listening on a specific port by typing in the following command and executing it.
lsof -i:(port number)
- In order to terminate any process that is using the port number to communicate, type in the following command and execute it.
kill $(lsof -t -i:"Port Number")
- The above command might not work on high privilege applications, therefore, execute the following command to immediately terminate any process communicating at a specific port.
kill -9 $(lsof -t -i:"Port Number")
- This command will immediately terminate any process communicating through the specified port number.
Kill Process on Port in Windows
- Press “Windows” + “R” to open Run prompt.
- Type in “cmd” and press “Shift” + “Ctrl” + “Enter” to open in administrative mode.
- Type in the following command to list the process communicating on a specific port.
netstat -ano | findstr :<yourPortNumber>
- This will list the process running on a specific port, note the “PID” for the program.
- In order to kill all the processes using the specific port, type in the following command and press “Enter” to execute it.
taskkill /PID <typeyourPIDhere> /F
- This will immediately terminate the program.