Find & Kill Process that Using A Specified Port

Port conflict usually happen whenever a service try to run and listen to a specific port while another server currently utilizing it. This kind error message widely known as one of indicator that you are experiencing port conflict.
port 8080 already in use
To solve port conflict, you have to check first: which process in your system that using port 8080
and kill it if possible.
There is a simple tool to check which process in your system that run an listen to a specific port: lsof
, it is an abbreviation of list of open files
. The command will list all opened files in the system. Check if your system does have it by type this command in your terminal:
lsof -v
To use it, you may type in format:
lsof -i :<port_number>
Notice that I add an argument -i
. We are using argument -i
since it allow lsof
selects the listing of files any of whose internet address matches the address specified in i.
So, to check which process utilize port 8080, you can use this:
sudo lsof -i :8080
To get all information, do use sudo
so any process run with sudo
can be listed as well. It will return something like this:
[email protected]:~$ sudo lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
main 4336 masgar 3u IPv6 54519 0t0 TCP *:http-alt (LISTEN)
Now that you have found the PID of a process that utilize port 8080
, you have an option to kill it or stay out of it. If you choose to kill it, you can use kill
, with format:
sudo kill -9 <PID number>
An argument -9
passed so by run kill
, you will kill a process immediately without having to wait the process to stop gracefully. Please do with cautious!
sudo kill -9 4336
Done! Your port 8080
is free now, just like Dobby.
If you have time to spare and want to be expert of lsof
, I'd recommend this article:
