It happens sometimes, that some applications block certain port even though it shouldn’t doing so. There are many reasons like bugs, locks, poor optimization. In such cases desired action is to kill guilty process, but first it has to be found.

The same story applies to case when it’s impossible to delete file or remove device.

# Find process that uses certain port.
lsof -i tcp:3000

# Find process that uses file / disk / device / etc.
lsof [file]

Those commands give command name, pid, and other info, but those two first are crucial. The easiest way from this point is to kill all processes.

lsof -i tcp:8000 | awk '{print $2;}' | tail -n +2 | xargs kill -kill

#sometimes sudo may be needed
lsof -i tcp:8000 | awk '{print $2;}' | tail -n +2 | xargs sudo kill -kill

Command tail help us skipping header.


http://stackoverflow.com/a/3855359 https://www.macobserver.com/tmo/article/terminal-using-lsof-when-files-wont-delete
⤧  Next post How to disconnect hanged ssh session? ⤧  Previous post Bash I/O redirection