Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am installing hadoop on my Ubuntu system. When I start it, it reports that port 9000 is busy.

I used:

netstat -nlp|grep 9000

to see if such a port exists and I got this:

   tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN

But how can I get the PID of the process which is holding it?

share|improve this question
    
See this wilddiary.com/find-the-process-using-a-given-port – Drona Nov 1 '15 at 13:28
    
up vote 63 down vote accepted

You can use netstat's -p option. You're already issuing it, but to get process information, you need to be the superuser:

$ sudo netstat -nlp | grep :80
tcp  0  0  0.0.0.0:80  0.0.0.0:*  LISTEN  125004/nginx

You can also use lsof:

$ sudo lsof -i :80 | grep LISTEN
nginx   125004 nginx    3u  IPv4   6645      0t0  TCP 0.0.0.0:http (LISTEN)
share|improve this answer
    
Note: under OSX, the -p option is for protocol rather than process. See this question – Bryan P Apr 10 at 16:51

Also you can use lsof utility. Need to be root.

# lsof -i :25
COMMAND  PID        USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
exim4   2799 Debian-exim    3u  IPv4   6645      0t0  TCP localhost:smtp (LISTEN)
exim4   2799 Debian-exim    4u  IPv6   6646      0t0  TCP localhost:smtp (LISTEN)
share|improve this answer
4  
This command will also give you processes with established connections, not just processes that are listening. – firelynx Aug 18 '15 at 10:10

This is best command I found to get the process id using port number:

sudo netstat -lpn |grep :9997
share|improve this answer
    
Once you have enough reputation (50) you can just comment, or better yet just upvote Chris' answer, if you deem that the best. The latter you can already do with 15 rep. – Anthon Apr 14 at 8:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.