Find and terminate a Windows Process by Port
Two common ports that may experience this error include 3000 and 8081, but can be any port.
Find the Process ID (PID)
For this, we can use netstat -a -o -n
to list all active connections.
In the list that gets spat out, find the line that has a Local Address
ending in the port you want to terminate - in this case we see:8080
. Note the value in the PID
column - we'll need that in a minute. NOTE: This value will most likely be different each time you start your program.
Confirm that PID is for the program in question
This step is optional, but I like to double check that I'm targeting the correct process before I terminate it.
To get a list of tasks running in cmd
we can run tasklist
which details everything actively running on your machine. See How to kill a task via terminal on Windows
Here, you can see that there are multiple node.exe
programs running, but only one of them has the PID3664.
Stop the running process
Now that you know that it is3664
PID, you can commence putting an end to our runaway process. The general format is taskkill /f /pid ####
, replacing the #### with the PID from above. If you try to run this without the /f
flag, you'll most likely be prompted to use the /f Force flag
by Windows.
And now you're set to start your process again!
Summary
Find what Process ID (PID) is occupying the port in question with
netstat -a -o -n
(Optional) Confirm this PID is for the expected program with
tasklist
Terminate the process with
taskkill /f /pid ####
(replace #### with your PID)
Last updated