How can I remove the current process/application which is already assigned to a port?
For example: localhost:8080
I know that is really old question, but found pretty easy to remember, fast command to kill app that are using port.
Requirements: npm@5.2.0^ version
npx kill-port 8080
You can also read more about kill-port here: https://www.npmjs.com/package/kill-port
If you are using GitBash
Step one:
netstat -ano | findstr :8080
Step two:
taskkill /PID typeyourPIDhere /F
(/F
forcefully terminates the process)
the first step
netstat -vanp tcp | grep 8888
example
tcp4 0 0 127.0.0.1.8888 *.* LISTEN 131072 131072 76061 0
tcp46 0 0 *.8888 *.* LISTEN 131072 131072 50523 0
the second step: find your PIDs and kill them
in my case
sudo kill -9 76061 50523
Step 1 (same is in accepted answer written by KavinduWije):
netstat -ano | findstr :yourPortNumber
Change in Step 2 to:
tskill typeyourPIDhere
Note: taskkill
is not working in some git bash terminal
In case you want to do it using Python: check Is it possible in python to kill process that is listening on specific port, for example 8080?
The answer from Smunk works nicely. I repeat his code here:
from psutil import process_iter
from signal import SIGTERM # or SIGKILL
for proc in process_iter():
for conns in proc.connections(kind='inet'):
if conns.laddr.port == 8080:
proc.send_signal(SIGTERM) # or SIGKILL
continue
For Windows users, you can use the CurrPorts tool to kill ports under usage easily: