Linux系统把软硬件都抽象成文件,所以通过文件可以追踪到很多重要信息,如读取的配置文件、打开的端口等。
下面是常见的用法:
默认测试文件名为text.txt
1,显示打开text.txt的进程:
lsof text.txt
2,显示占用某个端口的进程:
lsof -i :80
3,显示某个进程(进程名)打开的文件:
lsof -c process_name
4,显示某个进程号(pid)打开的文件:
lsof -p pid_number
5,显示某个用户打开的文件:
lsof -u user_name
默认输出字段解释:
[groot]$lsof -u groot
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
COMMAND:进程名字(默认下只取前9个字符);
PID:Process IDentification number;
USER:the user ID number or login name of the user to whom the process belongs;
FD:File Descriptor number or
cwd current working directory;
ltx shared library text(code and data);
mem memory-mapped file;
mmap memory-mapped device;
pd parent directory;
rtd root directory;
txt program text(code and data);
TYPE:is the type of the node associated with the file - e.g., GDIR, GREG, VDIR, VREG, etc.