lsof -i:端口號
eg:
lsof -i:80
lsof -i:21
[root@localhost ~]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 4168 root 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4170 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4171 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4172 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4173 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4174 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4175 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4176 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN) httpd 4177 nagios 3u IPv4 1917545678 0t0 TCP *:http (LISTEN)
lsof(list open files)是一個列出當前系統打開文件的工具。
實例2:查看誰正在使用某個文件,也就是說查找某個文件相關的進程
命令:
lsof /bin/bash
輸出:
[root@localhost ~]# lsof /bin/bash
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
bash 24159 root txt REG 8,2 801528 5368780 /bin/bash
bash 24909 root txt REG 8,2 801528 5368780 /bin/bash
bash 24941 root txt REG 8,2 801528 5368780 /bin/bash
[root@localhost ~]#
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
bash 24159 root txt REG 8,2 801528 5368780 /bin/bash
bash 24909 root txt REG 8,2 801528 5368780 /bin/bash
bash 24941 root txt REG 8,2 801528 5368780 /bin/bash
[root@localhost ~]#
---------------------------------------------------------------------------------------
實例6:列出某個程序進程所打開的文件信息
命令:
lsof -c mysql
說明:
-c 選項將會列出所有以mysql這個進程開頭的程序的文件,其實你也可以寫成 lsof | grep mysql, 但是第一種方法明顯比第二種方法要少打幾個字符了
-----------------------------------------------------------------------------------------
實例16:列出誰在使用某個端口
命令:
lsof -i :3306
dd