When starting a new service or app on Windows, you may find that the port you want to use is already occupied (listening) by another program (process). This article will show you how to find out which process is listening on a specific TCP or UDP port on Windows.
For example, you cannot run an IIS site on the default port 80 because the port is currently busy (if you are running multiple websites in IIS, you can run them on the same or different ports). So, how to find out which service or process that is listening on a port and kill it?
To get a complete list of the TCP and UDP ports that your computer is listening on, run the following command:
netstat -aon| find "LIST"
Or you can just enter the port number you are looking for:
netstat -aon | findstr ":80" | findstr "LISTENING"
- a – show network connections and open ports
- o – show the Process Identifier (PID) for each connection
- n – show addresses and port numbers in numeric format
The output of this command shows that TCP port 80 is being listened on (
LISTENING state) by the process with PID 16124.
You can identify the executable file of a process by its PID using Task Manager or the following command:
tasklist /FI "PID eq 16124"
You can replace all of the above commands with a one-liner:
for /f "tokens=5" %a in ('netstat -aon ^| findstr :80') do tasklist /FI "PID eq %a"
You can use a PowerShell one-line command to instantly get the name of the process listening on a specific port:
- TCP port:
Get-Process -Id (Get-NetTCPConnection -LocalPort 80).OwningProcess
- UDP port:
Get-Process -Id (Get-NetUDPEndpoint -LocalPort 53).OwningProcess
The tiny.exe process is listening on port 80 in our case.
Once you have the process identified, you can terminate it immediately by piping the results to the Stop-Process cmdlet:
Get-Process -Id (Get-NetTCPConnection -LocalPort 80).OwningProcess| Stop-Process
Check that port 80 is no longer in use:
Test-NetConnection localhost -port 80
To quickly find the path to the process executable in Windows, use the commands:
dir tiny.exe /s /p
Or you can use the built-in
where /R C:\ tiny
In our case, we found that the executable tiny.exe (lightweight HTTP server) listening on port 80 is located in the directory