For a project, I constantly need to find the process using a specific port and kill that process. I do this by:
lsof -i :portnumber
#read the pid
kill -9 pid
Since I do this a lot, I'm a bit bored to do so. So, I wonder if there is a way to kill a process using a specific port with only one command? If not, is there a python command that returns the pid of the process using a specific port, so that I can write a simple script to make the work?
This seems like a job for a shell command, eg:
lsof -i :80 | awk '{print $2}' | tail -1 | kill -9
Although if you really wanted to do it in python, you could wrap that command using the subprocess
module: subprocess