[linux命令]lsof
lsof命令是否强大,最近使用这个工具排查出了一个测试阶段发现的bug.
lsof基础用法
1
2
3
4
5
6
7
8
9
|
#查看端口暂用
#查看53端口进程
lsof -i:53
root@VM-8-10-ubuntu:/opt/blog# lsof -i:53
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dnsmasq 1280955 dnsmasq 4u IPv4 21540105 0t0 UDP *:domain
dnsmasq 1280955 dnsmasq 5u IPv4 21540106 0t0 TCP *:domain (LISTEN)
dnsmasq 1280955 dnsmasq 6u IPv6 21540107 0t0 UDP *:domain
dnsmasq 1280955 dnsmasq 7u IPv6 21540108 0t0 TCP *:domain (LISTEN)
|
1
2
3
4
|
root@VM-8-10-ubuntu:/opt/blog# lsof -i:53 -n -P
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 1306796 systemd-resolve 12u IPv4 21868306 0t0 UDP 127.0.0.53:53
systemd-r 1306796 systemd-resolve 13u IPv4 21868307 0t0 TCP 127.0.0.53:53 (LISTEN)
|
1
2
3
4
5
6
|
root@ubuntu:/opt/cybershield/agent# ps -ef | grep mysqld
mysql 1157 1 6 Jul11 ? 05:32:37 /usr/sbin/mysqld
root 118830 112405 0 18:17 pts/1 00:00:00 grep --color=auto mysqld
root@ubuntu:/opt/cybershield/agent# lsof -p 1157 | wc -l
72
|
1
2
3
4
5
6
7
|
lsof +D /tmp
root@VM-8-10-ubuntu:/tmp# lsof +D /opt/blog
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 1295496 root cwd DIR 252,2 4096 652942 /tmp
bash 1296856 root cwd DIR 252,2 4096 652942 /tmp
bash 1296873 root cwd DIR 252,2 4096 652942 /tmp
nvim 1296903 root cwd DIR 252,2 4096 652942 /tmp
|