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
just enter
fuser -k -n tcp 3000
in terminal , where 3000 is your port number
Use this:
sudo kill -9 $(lsof -t -i:9001)
If I was you,I would use
fuser -k -n tcp PORT
kill -9 PID
the below command will kill your running port
sudo kill -9 `sudo lsof -t -i:9001`
you can use
fuser -n tcp -k 9001
see more details in wikipedia
To kill the process based on port first we have to find out the relevant pid for given port and kill using that pid,
In my case i wanted to get the pid(process id) of 3000 port:
netstat -ltnp | grep -w '3000'
then find pid which is listening to tcp
tcp6 0 0 :::3000 :::* LISTEN 29972/node
you will get pid 29972
To kill this pid use below command
kill -9 29972
pseudo code for kill process based on port
netstat -ltnp | grep -w 'PORT'
and
kill -9 PID