1

File descriptors can be easily listed by executing ls -l /proc/$PID_OF_RUNNING_OR_PAUSED_PROCESS/fd/. But the commmand has to be running or paused at time of listing in order file descriptors still exist. How can I do the same for processes that finish right after execution? Is there any way to pause a command right after its execution? (e.g. ls -l /var/log/messages)

  • 1
    What exactly are you trying to determine? The open file descriptors, I get that, but what are you hoping that’s going to tell you? – Stephen Kitt Nov 12 '17 at 18:47
  • this is only for educational purposes. I'm just trying to see clear picture of file descriptors and linked open files of some commands. nothing extra special – rasty.g Nov 13 '17 at 7:33
  • I tried solutions from goo.gl/cBefJT but file descriptors seems to be created for parent process not for target command. They do not change no mather what target command is used. – rasty.g Nov 15 '17 at 10:38
1

You can run a process through strace and have it show you all opened files (and directories):

strace -o cmd.strace -e trace=open cmd
  • Yes, this is a much more robust approach than trying to get a snapshot of open file descriptors. Other trace filters which could be useful here are file (all system calls taking a file name as argument), desc (all file descriptor-related system calls) and memory (all memory mapping-related system calls, including mmap2). – Stephen Kitt Nov 13 '17 at 8:03

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.