Identify and Kill a Running Process Using a Specific Port on Windows and Ubuntu

Identify the Process Using a Port on Windows and Ubuntu

How to Identify the Process Using a Port on Windows and Ubuntu

kill port
ubuntu

In this blogpost, I will explore how to identify and terminate a process that is using a specific port on a Windows system & Ubuntu. This can be particularly useful when you need to free up a port that is being occupied by an unwanted or unknown application.


Windows

Step 1: Find out which process is using a particular port, follow these steps:

  1. Open Command Prompt as Administrator: Press Win + X and select "Command Prompt (Admin)" or "Windows PowerShell (Admin)" from the menu.
  2. Use the netstat Command: Type the following command, replacing <port> with the actual port number you are investigating:
    netstat -aon | findstr :<port>
    This command will display a list of all processes using the specified port, along with their PID (Process ID).The output will look something like this:
    TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       1234
    Here, 1234 is the PID of the process using port 8080

Step 2: Stop or kill the Process

Execute the command below, replacing <PID> with the PID of the process you want to stop:

taskkill /PID <PID> /F

The /F flag forces the process to terminate.


Ubuntu

Step 1: Identify the Process Using Port 80

You need to find out what is currently using port 80. Use this command:

sudo netstat -tulpn | grep :80

This will show the process ID (PID) of the service using the port.

Step 2: Stop the Process

Once you identify the process, you can decide whether to stop or configure it to use a different port. To stop the process, use:

sudo kill -9 [PID]

Replace [PID] with the actual process ID you found.

If the process is a service you recognize and want to keep running (like another web server), consider reconfiguring it to use a different port.