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
>
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