I'd like to be able to find out which process is currently using a certain port in Linux. Is there any way to do this?
5 Answers
You have a couple of options:
lsof -i tcp:80 will give you the list of processes using tcp port 80.
Alternatively,
sudo netstat -nlp will give you all open network connections.
- 3
lsof -i | grep {username}is also very useful, i.e.lsof -i | grep apacheLawrenceC– LawrenceC2011-10-30 03:20:00 +00:00Commented Oct 30, 2011 at 3:20 - 1For anyone wondering,
-n: don't resolve names,-l: display listening server sockets,-p: display PID/Program name for sockets.yellavon– yellavon2014-05-12 15:18:59 +00:00Commented May 12, 2014 at 15:18 - I usually add
-Ptolsof -i tcp:$PORTNUMBERso that the port gets printed back to me as a number.js.– js.2015-06-23 08:42:19 +00:00Commented Jun 23, 2015 at 8:42 - 1You also need an sudo on the lsof line, else it will silently fail.medoc– medoc2023-12-12 18:07:58 +00:00Commented Dec 12, 2023 at 18:07
I am using "CentOS 7 minimal" which has nor netstat neither lsof. But a lot of linux distributions have the socket statistics command (i.e. ss).
Here is an example of execution:
# ss -tanp | grep 6379 LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=2531,fd=4)) netstat -lp - 4on mac you have to add a protocol option to -p. so something like: netstat -lp tcp.vrish88– vrish882010-05-25 14:59:28 +00:00Commented May 25, 2010 at 14:59
In Linux, To find a process running on a port, do below:
lsof -i :<port_number> example:
lsof -i :8080 - Thanks for trying to help. This command was mentioned in the accepted answer. If you have something new, please edit your post.Ben N– Ben N2016-01-06 00:22:25 +00:00Commented Jan 6, 2016 at 0:22
also if you want to list running processes that are speaking TCP you can use
sudo netstat -tnp sudo to get processes you don't own -t for TCP -n for numeric -p for pid to get processes speaking UDP replace the -t with a -u
sudo netstat -unp
netstat -anb