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?
4
Answers
On windows use
netstat -nba | FINDSTR "LISTEN"
to get a list of processes (Pids) listening on a portif 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
if you want to do it all in one powershell command, you can go with
or
for redis
You can use batch(cmd.exe) for this task
To execute these bat files:
Which operating system are you using? The answer may differ depending on the type of the operating system, including different distributions.
For example, on some Linux distributions I’d rather use
ss -nltp
.Example:
Explained:
-n, --numeric don't resolve service names
(google.com –> 1.2.3.4)-l, --listening display listening sockets
(just the ports you’re listening at)-p, --processes show process using socket
(include sub processes locking sockets)-t, --tcp display only TCP sockets
A more general command would be
netstat
.Example:
$ netstat -nl
Please check the manual of
ss
for more information.Edit: Since you said you were using Windows, you can use this to list all the relevant processes (-n == numeric, -a == all, -o == show process id, -p TCP == show TCP only):
netstat -nao -p TCP
Last column would be the process ID, you can use
taskkill
to kill the process:taskkill /F /PID <PID>
Where
/F
says forcefully kill and/PID
indicates the next value is the process ID.Try following command :
The above command gives netstat information based on the following features:
Your output should look something like :