linux打开一个程序文件
How to find which files are opened by a Linux program? For example, when I run cat ~/.bashrc
, how to find out which files are opened by cat
?
如何查找Linux程序打开的文件 ? 例如,当我运行cat ~/.bashrc
,如何找出cat
打开了哪些文件?
You can achieve this by using strace
if the program “open” files using system calls.
如果程序使用系统调用“打开”文件,则可以通过使用strace
来实现。
For example, I run as this:
例如,我这样运行:
strace -o /tmp/st cat ./.bashrc
grep "^open" /tmp/st
It will prints out:
它将打印出:
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
open("./.bashrc", O_RDONLY) = 3
These files are opened. You can inspect the trace file (/tmp/st) to check all system called invoked by the command (cat here).
这些文件被打开。 您可以检查跟踪文件(/ tmp / st),以检查命令调用的所有系统(此处为cat)。
翻译自: https://www.systutorials.com/how-to-find-which-files-are-opened-by-a-linux-program/
linux打开一个程序文件