LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-08-2011, 11:03 AM   #1
laredotornado
Member
 
Registered: Apr 2011
Posts: 71

Rep: Reputation: 0
How to find what process is listening on a certain port?


Hi,

I'm using Ubuntu Linux 11.04. I want to figure out what process is listening on port 4444. I tried the following, but it lists a bunch of processes, and only one can listen on port 4444 ...

Code:
selenium@selenium:~$ lsof -w -n -i tcp:4444 -F ''
p3404
p5129
p5696
p7338
p15027
p26072
p27894
Ideally, I could just run a command that would return a single process ID. Any ideas how to modify the above or know of a different command to use? - Dave
 
Old 08-08-2011, 11:12 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Hello,

There are a few ways to do this, but I like using lsof most of the time, just like you did.
Code:
lsof +M -i4
Take a look at the man page if you want to know more about the lsof command.
Code:
man lsof
Cheers,

Josh
 
Old 08-08-2011, 12:46 PM   #3
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Also
Code:
netstat -lp --numeric-ports --protocol=inet | grep :4444
can be handy.
 
Old 08-09-2011, 08:35 AM   #4
laredotornado
Member
 
Registered: Apr 2011
Posts: 71

Original Poster
Rep: Reputation: 0
Hi,

eSelix, I tried your solution, but didn't get my process ID, only

Code:
netstat -lp --numeric-ports --protocol=inet | grep :4444
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
However, I'm successfully able to "telnet localhost 4444" and the process runs as a non-root user. I'm using bash shell, Ubuntu 11.04. Does your solution apply to some other setup?


Josh, What were you trying to show with "lsof +M -i4"? That doesn't show me my process that is listening on 4444.

Thanks, - Dave
 
Old 08-09-2011, 10:25 AM   #5
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
This is only warning, root is not neccessary for showing your own processes. This is corrected version:
Code:
netstat -lp --numeric-ports --protocol=inet 2>&1 | grep :4444
But in your example "telnet localhost 4444" the port 4444 is not opened by you, you only connect to it. Another program opened it.

Last edited by eSelix; 08-09-2011 at 10:31 AM.
 
Old 08-09-2011, 11:31 AM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Quote:
Josh, What were you trying to show with "lsof +M -i4"? That doesn't show me my process that is listening on 4444.

Thanks, - Dave
That was me failing to show you how to do it a different way
I normally use just the -i flag with lsof, but the +M -i4 was something that I was experimenting with a few days ago, and completely forgot that it doesn't show the actual numerical value of the port for the service on your system.
 
Old 08-09-2011, 11:35 AM   #7
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved to Linux-General
 
Old 08-09-2011, 01:10 PM   #8
laredotornado
Member
 
Registered: Apr 2011
Posts: 71

Original Poster
Rep: Reputation: 0
Hi eSelix, Thanks for sending an updated command but when I ran it, I didn't get any results ...

Code:
$ netstat -lp --numeric-ports --protocol=inet 2>&1 | grep :4444
$
I used the "telnet localhost 4444" to demonstrate that there was a process running on the machine listening at 4444, so theoretically, the command above should have returned its process id.

Thanks for any additional advice, - Dave
 
Old 08-09-2011, 03:53 PM   #9
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
For me it works, and show PID in second column:
Code:
lsof -i:4444
and your command from first post also works as expected.

So, what is your output of:
Code:
netstat -lp --numeric-ports --protocol=inet
lsof -w -n -i tcp:4444

Last edited by eSelix; 08-09-2011 at 04:13 PM.
 
1 members found this post helpful.
Old 08-10-2011, 08:15 AM   #10
laredotornado
Member
 
Registered: Apr 2011
Posts: 71

Original Poster
Rep: Reputation: 0
Hi, Here is the output I get from running the commands you suggested.

Code:
selenium@selenium:~$ netstat -lp --numeric-ports --protocol=inet
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:6015            0.0.0.0:*               LISTEN      3399/Xvfb       
udp        0      0 216.18.94.109:123       0.0.0.0:*                           -               
udp        0      0 127.0.0.1:123           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:123             0.0.0.0:*                           -               
udp        0      0 216.18.94.255:137       0.0.0.0:*                           -               
udp        0      0 216.18.94.109:137       0.0.0.0:*                           -               
udp        0      0 0.0.0.0:137             0.0.0.0:*                           -               
udp        0      0 216.18.94.255:138       0.0.0.0:*                           -               
udp        0      0 216.18.94.109:138       0.0.0.0:*                           -               
udp        0      0 0.0.0.0:138             0.0.0.0:*                           -               
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -               
udp        0      0 0.0.0.0:33086           0.0.0.0:*                           -               
selenium@selenium:~$ 
selenium@selenium:~$ 
selenium@selenium:~$ 
selenium@selenium:~$ lsof -w -n -i tcp:4444
COMMAND   PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    26439 selenium   10u  IPv6 18273130      0t0  TCP *:4444 (LISTEN)
selenium@selenium:~$ 
selenium@selenium:~$ 
selenium@selenium:~$ lsof -i:4444
COMMAND   PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    26439 selenium   10u  IPv6 18273130      0t0  TCP *:4444 (LISTEN)
selenium@selenium:~$
I'm using bash shell, if that matters, - Dave
 
Old 08-10-2011, 03:46 PM   #11
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
So "lsof" works for you too. For "netstat" I don't known why ipv6 is not displayed, as I am not using it. Maybe this is by option "--protocol=inet" or you can add option "-6"
 
Old 08-10-2011, 08:51 PM   #12
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
cat /etc/services | grep 4444 works to tell me which services are configured to listen on port 4444.

It reports this on CentOS.

Code:
cat /etc/services | grep 4444
krb524          4444/tcp                        # Kerberos 5 to 4 ticket xlator
krb524          4444/udp                        # Kerberos 5 to 4 ticket xlator
On Debian, it reports nothing. Reading /etc/services in Debian verifies that nothing was configured to listen on port 4444. Rather, in Debian, kerberos is configured to listen on ports 88, 749, 750, and 751.
 
Old 08-11-2011, 08:02 AM   #13
laredotornado
Member
 
Registered: Apr 2011
Posts: 71

Original Poster
Rep: Reputation: 0
Hi, Thanks for that, but I didn't register my process as a service, so nothing is appearing. Not to lose sight of what I was originally looking for, I just need an expression that will return the PID (and nothing else), of the process running on port 4444.

Thanks to all, - Dave
 
Old 11-25-2017, 07:26 PM   #14
Silomor
LQ Newbie
 
Registered: Nov 2017
Posts: 1

Rep: Reputation: Disabled
Listening to port 4444....

Nothing happens stoping on this screen, how to run? When im running eggshell

Last edited by Silomor; 11-25-2017 at 07:30 PM.
 
Old 11-27-2017, 06:09 PM   #15
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
How to find out which process is listening upon a port

Linux: Find Out Which Process Is Listening Upon a Port
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
If I have a nc process running and listening on a port... trist007 Linux - Newbie 3 02-09-2010 01:35 AM
find a port of a particular process ak.lokesh Linux - Newbie 1 03-19-2009 07:05 AM
Bind - Address already in use - How to get process listening on the port in C? hgrover Linux - Networking 0 03-21-2008 01:52 AM
Find the port on which Apache server is listening sharathkv Programming 5 04-14-2007 02:11 PM
find process runnning on particular port varunbihani Linux - Newbie 1 05-19-2005 09:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration