查看是那个进程在占用哪个端口,可以考虑使用:
- netstat – a command-line tool that displays network connections, routing tables, and a number of network interface statistics.
- fuser – a command line tool to identify processes using files or sockets.
- lsof – a command line tool to list open files under Linux / UNIX to report a list of all open files and the processes that opened them.
- /proc/$pid/ file system – Under Linux /proc includes a directory for each running process (including kernel processes) at /proc/PID, containing information about that process, notably including the processes name that opened port.
步骤1:
# netstat -tulpn
Sample outputs:
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1138/mysqld tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 850/portmap tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1607/apache2 tcp 0 0 0.0.0.0:55091 0.0.0.0:*
TCP port 3306 was opened by mysqld process having PID # 1138. You can verify this using /proc, enter:# ls -l /proc/1138/exe
https://www.cyberciti.biz/faq/what-process-has-open-linux-port/
另外可以参考
http://unix.stackexchange.com/questions/106561/finding-the-pid-of-the-process-using-a-specific-port
On Linux, you must be root or the other user to get process information for processes running as other users, so prepending sudo is most of what you need. In addition to that, on modern Linux systems, ss is tool to use to do this:
$ sudo ss -lptn 'sport = :80'
State Local Address:Port Peer Address:Port
LISTEN 127.0.0.1:80 *:* users:(("nginx",pid=125004,fd=12))
LISTEN ::1:80 :::* users:(("nginx",pid=125004,fd=11))

1241

被折叠的 条评论
为什么被折叠?



