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

In Windows, Every software or tool has one or multiple processes with dependencies.

For example, If you installed apache tomcat on windows, start the server, It listens on the 8080 port by default.

Sometimes, if any process runs on the same port number, You will get an error 8080 is already in use, Please try different ports

This post covers ways to check process id and name details for a given port

nestat command to get the process id

netstat command list out all process and type of connection, process id as well as the hostname

This command lists the following information

  • protocol like TCP or UDP

  • Local address

  • Foreign Address


  • Process ID

    Here is a command to know the process id and protocol type

C:\>netstat -aon

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP                 LISTENING       4
  TCP              LISTENING       3852
  TCP    ESTABLISHED     2268
  TCP    [::]:80                [::]:0                 LISTENING       4
  UDP           *:*                                    6100

From the above result, you can filter data using pipe symbol with the findStr function

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

Another way, if you know the process id, you can use the tasklist command as seen below

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

Find out Process name and id using PowerShell in windows

PowerShell is a powerful command-line tool to know process details

The below command finds out the process name for the 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

below the command find out the process id for the given port number

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

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