Colin Harrington

Which process has that port open? (Linux / netstat -anp)

by on Dec.21, 2010, under General, Linux

Occasionally, I’ll have an application that I’m working on die spectacularly and still hold on to the open sockets / ports.  in Java you would see the Address already in use for an open port much like: Address already in use
at Method)

It took me a second to figure out how locate the process, but it turned out to be a really easy task using the netstat command by executing ‘netstat -anp | grep 8080‘ (a = all interfaces, n = numeric, p = show pid)  This isn’t perfect since it will still show you anything with a pid of 8080 (the port number I was looking for), but its a great quick-and dirtry way to identify the process.  and once I’ve found it I can kill it with a ‘kill -9 <pid>

user@machine:~/$ netstat -anp | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      19884/java
user@machine:~/$ kill -9 19884

Which reminds me of this classic (please excuse the profanity):

Windows => netstat -ano
OSX => lsof -i -P

1 Comment for this entry

  • O-Man!

    Nice and easy though, i killed a task which i need it was a console inside it that was the problem :/
    ahwell we all learn from our mistakes :P

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!