Capture STDIN / STDERR / STDOUT of a process AFTER it's been started, using command line?
This is possible but it's not pretty. The process is as follows:
- use
gdb
to attach to the already running process - run
p close(<fd>)
where<fd>
is the file descriptor you want to change - run
p creat("<path to file">, <perms>)
to send the output of the closedfd
somewhere else
See This Link for more detailed information
Why do you want to do that??
It is not possible in a portable Posix-ly way! Maybe open
-ing the /proc/1234/fd/0
and /proc/1234/fd/1
and /proc/1234/fd/3
pseudo-files (for process 1234) could be an ugly possiblity! And even that might not work in some cases (e.g. for pipes).
In particular, I believe that the semantics of SIGPIPE
sent to the process if nobody is reading a pipe would be broken...
And I don't believe that you would be able to keep the pseudo-tty quality of e.g. stdout .
So basically, you'll better find a different way to achieve your overall goals, which you did not explain explicitly.
If your use-case is some weird configure
script, you could restart it and feed it with some script of your own (in shell, python, perl, etc...). Don't lose time to try to catch an existing configure
process, just restart it appropriately.
Look also at the screen
command (and how it is implemented!)