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

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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)
process file-descriptors
add a comment |Â
up vote
1
down vote
favorite
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)
process file-descriptors
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
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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)
process file-descriptors
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)
process file-descriptors
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
add a comment |Â
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
add a comment |Â
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
Yes, this is a much more robust approach than trying to get a snapshot of open file descriptors. Othertracefilters which could be useful here arefile(all system calls taking a file name as argument),desc(all file descriptor-related system calls) andmemory(all memory mapping-related system calls, includingmmap2).
â Stephen Kitt
Nov 13 '17 at 8:03
add a comment |Â
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
Yes, this is a much more robust approach than trying to get a snapshot of open file descriptors. Othertracefilters which could be useful here arefile(all system calls taking a file name as argument),desc(all file descriptor-related system calls) andmemory(all memory mapping-related system calls, includingmmap2).
â Stephen Kitt
Nov 13 '17 at 8:03
add a comment |Â
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
Yes, this is a much more robust approach than trying to get a snapshot of open file descriptors. Othertracefilters which could be useful here arefile(all system calls taking a file name as argument),desc(all file descriptor-related system calls) andmemory(all memory mapping-related system calls, includingmmap2).
â Stephen Kitt
Nov 13 '17 at 8:03
add a comment |Â
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
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
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. Othertracefilters which could be useful here arefile(all system calls taking a file name as argument),desc(all file descriptor-related system calls) andmemory(all memory mapping-related system calls, includingmmap2).
â Stephen Kitt
Nov 13 '17 at 8:03
add a comment |Â
Yes, this is a much more robust approach than trying to get a snapshot of open file descriptors. Othertracefilters which could be useful here arefile(all system calls taking a file name as argument),desc(all file descriptor-related system calls) andmemory(all memory mapping-related system calls, includingmmap2).
â 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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