Search code examples
localhostport

How to list all processes/services running on different ports


Is there a command that lists all the services that are running on different ports of localhost?

In my case, when I'm working on an Angular app, I may run it on localhost:4200, a React app on localhost:3000 and a Redis server on localhost:6379, etc.

Is there a way of knowing if these are running and how can I kill/stop them?


Solution

  • On windows use netstat -nba | FINDSTR "LISTEN" to get a list of processes (Pids) listening on a port

    if you need to find a specific port, then pipe it through findstr twice netstat -nba | FINDSTR "LISTEN" | FINDSTR "3000"

    In powershell you can then use Stop-Process CMDlet with the Id option to stop the process

    Stop-Process -Id 1234
    

    if you want to do it all in one powershell command, you can go with

    Stop-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess -Force
    

    or

    Stop-Process -Id (Get-NetTCPConnection -LocalPort 6379).OwningProcess -Force
    

    for redis