根据文件句柄号获取文件名

根据文件句柄号获取文件名

我正在一个系统上运行strace -p 1234 -o strace.out,怀疑该进程的1234性能很差。我看到这些reads需要几乎一分钟才能完成:

read(11, "\0\335\0\0\6\0\0\0\0\0\20\27m\3708\341\246\247\365\374\334\0274-X#\21!xs\10\25"..., 2064) = 221

我希望找出文件名与文件句柄相关联11

更新

$ sudo strace -yp 3549 -o strace.out.2
strace: invalid option -- y
usage: strace [-dffhiqrtttTvVxx] [-a column] [-e expr] ... [-o file]
              [-p pid] ... [-s strsize] [-u username] [-E var=val] ...
              [command [arg ...]]
   or: strace -c [-e expr] ... [-O overhead] [-S sortby] [-E var=val] ...
              [command [arg ...]]
-c -- count time, calls, and errors for each syscall and report summary
-f -- follow forks, -ff -- with output into separate files
-F -- attempt to follow vforks, -h -- print help message
-i -- print instruction pointer at time of syscall
-q -- suppress messages about attaching, detaching, etc.
-r -- print relative timestamp, -t -- absolute timestamp, -tt -- with usecs
-T -- print time spent in each syscall, -V -- print version
-v -- verbose mode: print unabbreviated argv, stat, termio[s], etc. args
-x -- print non-ascii strings in hex, -xx -- print all strings in hex
-a column -- alignment COLUMN for printing syscall results (default 40)
-e expr -- a qualifying expression: option=[!]all or option=[!]val1[,val2]...
   options: trace, abbrev, verbose, raw, signal, read, or write
-o file -- send trace output to FILE instead of stderr
-O overhead -- set overhead for tracing syscalls to OVERHEAD usecs
-p pid -- trace process with process id PID, may be repeated
-s strsize -- limit length of print strings to STRSIZE chars (default 32)
-S sortby -- sort syscall counts by: time, calls, name, nothing (default time)
-u username -- run command as username handling setuid and/or setgid
-E var=val -- put var=val in the environment for command
-E var -- remove var from the environment for command

答案1

当您运行 Linux 时,您可以找到与您的 uid 拥有的任何进程(或所有进程,如果是 root)的任何文件描述符关联的文件名ls

例如:

ls -lF /proc/1234/fd/11

答案2

来自精美手册:

   -y          Print paths associated with  file  descriptor  argu-
               ments

相关内容