Friday, February 13, 2009

Detect Which Process is Using Which Port

On my previous post I documented the way I access the desktop on my home PC or my wife's laptop, using VNC and ssh.

Sometimes the connection is cut for some reason, and may leave behind an ssh process hogging a forwarded port, preventing me from connecting again. The solution is simple - kill that process.

But in order to kill the rogue process I need to find its process id. Now how do I do that? Easy - by using netstat to look up which process is listening to one of the forwarded ports:
netstat -lnpA inet | grep -e 590.


  1. A lot easier would be:
    lsof -i :PORT or lsof -in :PORT

    if still "married" with netstat
    netstat -nlpt
    would shorten the list.