How to list file descriptors of any command before it finishes?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
2












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)







share|improve this question


















  • 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














up vote
1
down vote

favorite
2












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)







share|improve this question


















  • 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












up vote
1
down vote

favorite
2









up vote
1
down vote

favorite
2






2





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)







share|improve this question














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)









share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '17 at 21:39









Hauke Laging

53.6k1282130




53.6k1282130










asked Nov 12 '17 at 18:31









rasty.g

33326




33326







  • 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




    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




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




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




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




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 Answer
1






active

oldest

votes

















up vote
1
down vote













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





share|improve this answer




















  • 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







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f404090%2fhow-to-list-file-descriptors-of-any-command-before-it-finishes%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













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





share|improve this answer




















  • 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














up vote
1
down vote













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





share|improve this answer




















  • 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












up vote
1
down vote










up vote
1
down vote









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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '17 at 21:41









Hauke Laging

53.6k1282130




53.6k1282130











  • 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
















  • 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















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




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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f404090%2fhow-to-list-file-descriptors-of-any-command-before-it-finishes%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)