DEV Community

eddiejpot
eddiejpot

Posted on

How to kill a process on localhost port on Ubuntu & Windows

We'll be using port number 3000 as the example

Ubuntu

Option 1:

Step One:
Get the process id

sudo netstat -lpn |grep :3000
Enter fullscreen mode Exit fullscreen mode



You will get an output similar to this

tcp6  0  0 :::3000    :::*    LISTEN    1234/node
Enter fullscreen mode Exit fullscreen mode

Step Two:
Now that you have the process id - which is 1234 ​in this example
Kill the process using the code below

kill -p 1234  OR  kill -9 1234
Enter fullscreen mode Exit fullscreen mode


Option 2:

fuser -k 3000/tcp
Enter fullscreen mode Exit fullscreen mode


Windows

Step One
Open up cmd.exe (we may need to run it as an administrator, but this isn't always necessary). Run the below command:
netstat -ano | findstr :<PORT>

netstat -ano | findstr :3000
Enter fullscreen mode Exit fullscreen mode



The arrow shows the PID (process identifier). Locate the PID of the process that's using the port you want.
Alt Text

Step Two
taskkill /PID <PID> /F

taskkill /PID 4692 /F
Enter fullscreen mode Exit fullscreen mode


Step Three
You can check if the operation was successful by re-running the command in "Step 1". You shouldn't see any more search results for that port number.

Top comments (0)