Linux/unix 通过查询进程pid 找出相关文件
2016-01-21 00:00
441 查看
摘要: Linux/unix 通过查询进程pid 找出相关文件
下面是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 -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 符号链接文件
一、查询进程打开的文件的方法
You can find the exe easily by these ways, just try it yourself.ll /proc/<PID>/exe
pwdx <PID>
lsof -p <PID> | 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 其它方面的应用
参考:http://my.oschina.net/guol/blog/37304lsof -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 符号链接文件
三、参考其他博文
http://www.cyberciti.biz/faq/find-out-which-service-listening-specific-port/相关文章推荐
- Unix 即将迎来 50 岁
- Linux VS Unix:Linux欲一统天下 Unix不死
- 看UNIX高手的10个习惯第1/2页
- javascript iframe中打开文件,并检测iframe存在否
- 通过PHP修改Linux或Unix口令的方法分享
- mysql unix准换时间格式查找指定日期数据代码
- php strtotime 函数UNIX时间戳
- 安全检测Unix和Linux服务器安全设置入门精讲
- Powershell使用OpenFileDialog打开文件示例
- 分享20个Unix/Linux 命令技巧
- PHP使用gmdate实现将一个UNIX 时间格式化成GMT文本的方法
- Mac OS下配置远程Linux 服务器SSH密钥认证自动登录
- C的温故知新
- 使用golang和docker守护进程交互
- Alice梦游UNIX仙境
- LINUX之前UNIX的历史
- 关于GNU计划
- Unix 调试的瑞士军刀:lsof
- expect 打开文件