How to find process id name listen to TCP/UDP ports in windows

In Windows, every software or tool typically has one or multiple processes with dependencies. For instance, if you have installed Apache Tomcat on Windows and started the server, it usually listens on port 8080 by default.

However, issues may arise if another process is already using the same port. In such cases, you might encounter an error message like 8080 is already in use. Please try different ports.

This post covers various methods to check process IDs and obtain details for a given port.

Using the netstat Command to Retrieve Process ID

The netstat command lists all processes, connection types, process IDs, and hostnames.

The following information is displayed:

  • Protocol (TCP or UDP)
  • Local address
  • Foreign address
  • State (e.g., LISTENING, ESTABLISHED, TIME_WAIT)
  • Process ID

Here is an example command to retrieve the process ID and protocol type

C:\>netstat -aon

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4
  TCP    127.0.0.1:3003         0.0.0.0:0              LISTENING       3852
  TCP    192.168.29.53:31106    116.202.172.174:443    ESTABLISHED     2268
  TCP    [::]:80                [::]:0                 LISTENING       4
  UDP    0.0.0.0:3702           *:*                                    6100

To filter data for a specific port, you can use the findStr function with a pipe symbol:

C:\>netstat -ano | findStr "3000"
  TCP    0.0.0.0:3000           0.0.0.0:0              LISTENING       16876
  TCP    [::]:3000              [::]:0                 LISTENING       16876

If you know the process ID, you can use the tasklist command to identify the process name

The following find out process id is using which port

C:\>tasklist /fi "pid eq 16876"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
node.exe                     16876 Console                    1     78,472 K

Finding Process Name and ID Using PowerShell in Windows

PowerShell is a powerful command-line tool for obtaining process details. The following commands showcase its capabilities

To find the process name for a given port

PS C:\> Get-Process -Id (Get-NetTCPConnection -LocalPort 3002).OwningProcess

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    281      68   127908      98768      12.64  18548   1 node

To find the process ID for a given port number

PS C:\> Get-NetTCPConnection -LocalPort 3002| Format-List


LocalAddress   : 0.0.0.0
LocalPort      : 3002
RemoteAddress  : 0.0.0.0
RemotePort     : 0
State: Listen
AppliedSetting :
OwningProcess: 18548
CreationTime   : 29-04-2021 12:47:28
OffloadState   : InHost

These PowerShell commands provide information about the process associated with the specified port, including details such as handles, memory usage, and the process name.

By using these commands, you can efficiently list all processes information associated with specific ports on a Windows system.