I am trying to kill a process in the command line for a specific port in ubuntu.
If I run this command I get the port:
sudo lsof -t -i:9001
sudo fuser -n tcp -k [port_number]
sudo lsof -t -i:[port_number]
It gives me an error OSError: [Errno 98] Address already in use. using the following method solved my error in Ubuntu.(VERSION="18.04.4 LTS (Bionic Beaver)")
$ sudo netstat -lpn |grep :5000
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 25959/uwsgi
$ fuser -k -n tcp 5000
5000/tcp: 25959
Hope it will help someone!
FOR UBUNTU 1- Find what application/process is using the pro, type:
sudo netstat -lpn |grep :8080
and press Enter.
You will get an output similar to this one
tcp6 0 0 :::8080 :::* LISTEN 6782/java
2- I have got the process Id, which is 6782, now this is the process that is using port 8080.
3- Kill the process, type:kill 6782
kill 6782
There are some process which does not shown using normal netstat command, so you have to check it using sudo.
Do sudo netstat -lpn |grep :8080. Process running by system does not show PID, to get PID of this process you will have to run it using sudo
And then killl the process using port 8080. You may have to use sudo here as well. So to kill this process use sudo kill -9 PID
sudo kill `sudo lsof -t -i:9001`
you don't have to add the -9signal option
Try sudo fuser PORT/tcp -k
Replace PORT with the port you want to kill, for example 80