一、查询进程打开的文件的方法
You can find the exe easily by these ways, just try it yourself.
ll /proc//exe
pwdx
lsof -p | grep cwd
下面是lsof 的官方解释:
lists on its standard output file information about
files opened by processes for the following UNIX dialects:
An open file may be a regular file, a directory, a block special file,
a character special file, an executing text reference, a library, a
stream or a network file (Internet socket, NFS file or UNIX domain
socket.) A specific file or all the files in a file system may be
selected by path.
Instead of a formatted display, lsof will produce output that can be
parsed by other programs. See the -F, option description, and the
OUTPUT FOR OTHER PROGRAMS section for more information.
二、lsof 其它方面的应用
lsof -c xxx 只显示COMMAND列中包含xxx的
lsof -a 后面跟的两个参数都满足时才显示结果
lsof -u name 显示进程属主是name的打开的文件
lsof +d /dir/ 显示dir目录下被打开的文件
lsof +D /dir/ 同上,不过会递归下级目录
lsof -d FD 显示指定文件描述符的进程
lsof -i 显示符合条件的进程情况
-i:port
-i tcp/udp
-i hostname
FD 列内容
cwd 当前的工作目录
txt 程序文件 code&&date
mem 内存映射文件
err FD的错误信息
rtd root目录
r 只读 w 可写 u读写
xu/xr/xw x是数字 表示文件描述符是/proc/PID内容/fd/x文件
TYPE 列是相关文件的类型
DEL 一个已经被删除的索引文件
REG 常规文件
CHR 字符设备文件
DIR 目录
FIFO FIFO文件
LINK 符号链接文件
三、参考其他博文