13

If, on Linux, I strace a process, then the reads and writes are shown with the file descriptor handle number. If I look in /proc/$PID/fd I can see the symlinks to the files that correspond to the fd number (if applicable).

Is there anyway to get strace to do this look up for me and (by dereferencing the symlink) show me the filename inside the strace output? It already looks up Linux errno's and truncates & encodes strings, so can it do this too?

Update: I know strace will have shown the open call which shows the path & fd. Which is fine for short running processes. But presume I have a very long running process (measured in days), and did not run the whole thing under strace, merely connect to it later with strace -p.

Amandasaurus
  • 30,211
  • 62
  • 184
  • 246
  • It will previously have shown the corresponding `open()` syscall, which includes the path. – Michael Hampton Oct 08 '15 at 09:01
  • Are you saying you want strace info from a process, without running strace at the time the system calls are happening? – Ryan Babchishin Oct 08 '15 at 11:56
  • No, I want to run strace on a process and see what's going on. But rather than `write(12, 'done', 4) = 4`, I'd rather see `write(4 [/var/log/prog], 'done', 4) = 4` (or similar). I want to see the filename of the fd in the strace output when there's a `read`/`write`/etc call – Amandasaurus Oct 08 '15 at 12:59

1 Answers1

24

A quick look through the fine manual turns up:

   -y          Print paths associated with  file  descriptor  argu-
               ments.
thrig
  • 1,626
  • 9
  • 9