识别在Linux上打开特定进程的文件 [英] Identify the files opened a particular process on linux

查看:91
本文介绍了识别在Linux上打开特定进程的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个脚本来标识在linux上打开特定进程的文件

I need a script to identify the files opened a particular process on linux

要识别fd:

>cd /proc/<PID>/fd; ls |wc –l  

我希望看到一个数字列表,该数字列表是该过程中使用的文件描述符编号的列表.请告诉我如何查看该过程中使用的所有文件. 谢谢.

I expect to see a list of numbers which is the list of files descriptors' number using in the process. Please show me how to see all the files using in that process. Thanks.

推荐答案

您可能要使用的命令是lsof.与挖掘/proc相比,这是一个更好的主意,因为该命令是获取系统信息的更清晰,更稳定的方法.

The command you probably want to use is lsof. This is a better idea than digging in /proc, since the command is a more clear and a more stable way to get system information.

lsof -p pid

但是,如果您对/proc东西感兴趣,您可能会注意到文件/proc/<pid>/fd/x是与其关联文件的符号链接.您可以使用readlink命令读取symlink值.例如,这表明终端stdin已绑定到:

However, if you're interested in /proc stuff, you may notice that files /proc/<pid>/fd/x is a symlink to the file it's associated with. You can read the symlink value with readlink command. For example, this shows the terminal stdin is bound to:

$ readlink /proc/self/fd/0
/dev/pts/43

或者,要获取某个进程的所有文件,

or, to get all files for some process,

ls /proc/<pid>/fd/* | xargs -L 1 readlink

这篇关于识别在Linux上打开特定进程的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆