I have a command to check the port and kill specific pid running on that port. But I want to modify it to,
- Check port is busy or available
- If the port is busy then kill the pid
How can I do this?
Code is given below.
sudo netstat -nlpt | grep 2020 | awk '{print $7}' | sed s+/.*++g | sort -u | xargs -i kill -kill {}
You can make use of this command to delete port in Ubuntu.
The lsof command or list of open files with -i flag will find out all the running process of specific port and gives the corresponding process Id. The kill option will terminate the process with pid given from the lsof command.
So if you want to kill process running on port 3000, you will have to execute the following command