Find process using port number in Bash

Something that has bugged me recently is that when I go to proxy on a particular port, the port is already in use and I get the following error.

bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 8090
Could not request local forwarding.


So I had a quick look to find out how to locate the process hogging the port. All I need to do is use the lsof command.

lsof -i:8090

This command returns a list of open processes on this port.

Something like…

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 75782 eoin 5u IPv6 0x01c1c234 0t0 TCP localhost:8090 (LISTEN)

To free the port, kill the process using it…
kill 75782

 

[Update: Simpler solution found]

Easier to kill all ssh processes and restart them (if you use terminal aliases!), since in my case it is always an ssh process that is hogging the port.

killall ssh

2 Kommentare zu „Find process using port number in Bash

  1. Nice tip. I’ve been using:

    ps ax | grep ssh | grep -v grep

    to check for ssh sessions, and killing the process from there.

    Another way to check the port usage is:

    netstat -an | grep 8090

Hinterlasse einen Kommentar