ubuntu-查看端口占用程序,或者程序占用端口

127 阅读1分钟
# 根据进程名找到进程号,进而根据进程号找到端口
dev@dev-VirtualBox ~ $ ps -ef |grep mysql
mysql      881     1  0 10:06 ?        00:00:03 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
dev       2087 31311  0 14:49 pts/1    00:00:00 grep --color=auto mysql
dev@dev-VirtualBox ~ $ 
dev@dev-VirtualBox ~ $ sudo netstat -nltp |grep 881
tcp        0      0 0.0.0.0:6033            0.0.0.0:*               LISTEN      881/mysqld 
dev@dev-VirtualBox ~ $
# 根据进程名找到端口 
dev@dev-VirtualBox ~ $ sudo netstat -nltp |grep mysql
tcp        0      0 0.0.0.0:6033            0.0.0.0:*               LISTEN      881/mysqld          
dev@dev-VirtualBox ~ $ 
# 根据端口找到进程
dev@dev-VirtualBox ~ $ sudo netstat -nltp |grep 6033
tcp        0      0 0.0.0.0:6033            0.0.0.0:*               LISTEN      881/mysqld          
dev@dev-VirtualBox ~ $