Find and kill a port was already in use

Kobe
1 min readNov 14, 2022

--

Some time when you try to start an application ( server ) and application failed to start with error

Server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that's listening on port 8080
configure this application to listen on another port.

The problem when your app started with a background processing and when you close the Code Editor , Command line the process still running

Just simple kill it and restart application

sudo lsof -i :<PortNumber>

kill -9 <PID>

Example: sudo lsof -i :8080

sudo lsof -i :8080

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 63207 haithai 56u IPv6 0xb7a4136880cbaf4f 0t0 TCP *:http-alt (LISTEN)

From the command we can see our PORT(8080) running below PID : 63207

Kill the process with command kill -9 63207

kill -9 63207

Another way to find the PID with netstat command.


#8080 - port number needs to be unclocked
# macOs
sudo lsof -i tcp:8080
# common way
netstat -vanp tcp | grep 8080
#centOs
netstat -vanp --tcp | grep 8080

#after finding PID number of process
#run the following command:
kill -9 <PID>
#where <PIP> replace with proper PID number

--

--

Kobe
Kobe

Written by Kobe

I’m working at KMS-Technology company. I love code (▀̿Ĺ̯▀̿ ̿) — Full Stack Software Engineer

No responses yet