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.

  • It will previously have shown the corresponding open() syscall, which includes the path. – Michael Hampton Oct 8 '15 at 9: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 8 '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 – Rory Oct 8 '15 at 12:59

A quick look through the fine manual turns up:

   -y          Print paths associated with  file  descriptor  argu-

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.