lsof
发布日期:2021-05-07 18:06:22 浏览次数:30 分类:精选文章

本文共 912 字,大约阅读时间需要 3 分钟。

参考

list open file
使用lsof,可以查看到任何打开的文件的信息。
linux中一切可以看做文件,普通文件,管道,网络文件(例如socket),设备等都是文件。

1.lsof

# lsof
列出所有活动进程打开的文件。
这里写图片描述

解释第一行的几个值:

FD:file descriptor 文件描述符

  • cwd – Current Working Directory
  • txt – Text file
  • mem – Memory mapped file
  • mmap – Memory mapped device
  • NUMBER – Represent the actual file descriptor. The character after the number i.e ‘1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.

TYPE, Some of the values of TYPEs are

  • REG – Regular File
  • DIR – Directory
  • FIFO – First In First Out(先进先出是队列)
  • CHR – Character special file

DEVICE:指定磁盘名称

NODE: 索引节点,文件在磁盘上的标识

2.lsof 文件名

列出打开了指定文件的进程
# lsof /var/log/syslog

3.lsof -p 进程pid

列出被指定的进程所打开的文件
# lsof -p pid
这里写图片描述

4. lsof -u username

显示指定用户下打开的文件

5. lsof -i

这个命令和网络相关,显示所有的网络连接
这里写图片描述

按条件过滤的

  • lsof -i tcp #查看协议tcp的连接
  • lsof -i udp #udp协议的连接
  • lsof -i4 # ipv4
  • lsof -i6 # ipv6
  • lsof -i -n # 不把ip转化为hostname
  • lsof -i :22 # 查看22号端口被哪个进程占用,监听
上一篇:/proc初识
下一篇:aide入侵检测工具与crontab

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年03月22日 00时59分12秒