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 java.net.BindException: Address already in use for an open port much like:

java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
...

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):

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


8 Comments 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

  • laser hair therapy

    I really love to write and I’m pretty good at it. But whenever I try to write a story or something I start off good but always end up throwing it away–I can never seem to finish it. . . Sometimes I have a good idea that I really like but it’s just hard for me to write a story about and keep going. I like creative writing, but now I’ve almost given up because I can’t even write a short story. HELP!!! What should I do?. Any good creative writing websites to help me get started? Books?. I’m DESPERATE!!.

  • finance analyst

    I post them, they get 1 or 2 views, and then no more. I would like my content to do more than just give me a few views…how do I get them on the search engines or something like that? Will no one ever go to my blog just because I don’t post every day?.

  • Shiela Orhenkowski

    Do you have a spam issue on this site; I also am a blogger,
    and I was curious about your situation; many of us have developed some nice procedures and we are looking to trade strategies with others, why not shoot me
    an email if interested.

  • Amazon

    Thanks for finally talking about > Which process has that port
    open? (Linux / netstat -anp) – Colin Harrington < Liked it!

  • eläkeläiselle

    I’m amazed, I must say. Seldom do I come across a blog that’s both
    equally educative and entertaining, and without a doubt, you have hit the nail on the
    head. The problem is something that not enough men and women are speaking intelligently about.
    I am very happy I found this in my search for something relating to this.

  • pikavippi

    I hardly leave a response, however I browsed a few of
    the comments on this page Which process has that port open? (Linux
    / netstat -anp) – Colin Harrington. I do have some questions
    for you if it’s okay. Is it only me or does it look as if
    like a few of these remarks look like they
    are written by brain dead folks? :-P And,
    if you are posting at other sites, I would like to keep up
    with you. Could you make a list of all of all your public pages
    like your Facebook page, twitter feed, or linkedin profile?

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!