Sometimes during day to day development I get a Port already in use
error (or a variant of it), and I quickly want to see which process I forgot to terminate.
We can get the PID of the process occupying a port (e.g. 8888) with:
$ lsof -ti:8888
In order to quickly kill it, we can just pipe the output into the kill
command
$ lsof -ti:8888 | kill -9
Before using macs I was a firm believer in the power of `netstat -tpnl` for this particular problem, the netstat implementation under OSX leaves stuff to be desired so I switched to lsof as well.
Had a nasty annoyance once when I didn’t realise that lsof is list-of-open-files and a particular process had privileges and it would show under netstat but not lsof.. As usual, running with `sudo` solved it ;P
0 Pingbacks