Find out which PID listens on socket

Posted Over 13 years ago. Visible to the public.

Show all sockets (Unix & TCP/UDP), both listening and established ones:
netstat -anp

To limit the output e.g. to listening TCP sockets:
netstat -anp | grep tcp | grep LISTEN
...
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 28683/server
...

This means: A tcp v4 socket listening on port 3000 on all IP adresses (0.0.0.0 is synonym to 'all interfaces on the machine').

The last column includes the PID, kill -9 28683 should exit the process and clean up the socket.

Thomas Eisenbarth
Last edit
Over 13 years ago
Keywords
process, ps
License
Source code in this card is licensed under the MIT License.
Posted by Thomas Eisenbarth to makandra dev (2010-08-31 10:13)