How to detect and solve port occupancy in Linux
Sometimes we may find that a program is occupying a port, and we cannot use this port.
We can use two commands to solve this problem.
Find the program
netstat -anp | grep 4000
tcp6 0 0 :::4000 :::* LISTEN 81970/hexo
Here we can find the PID 81970 before the program name. (You may need sudo to see the process name, and netstat may require net-tools to be installed.)
Kill the program
kill -9 81970
If the permissions are not enough, add sudo before the command.
Content licensed under CC BY-NC-SA 4.0.