-
-
Save treywelsh/6d465e785b5728ca228ee829fb672c86 to your computer and use it in GitHub Desktop.
How to redirect a running process output to a file and log out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctrl-z | |
bg | |
./fdredir.bash | |
# shell | |
disown |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#seems to be existing scripts: https://www.isi.edu/~yuri/dupx/ | |
if [ $# - lt 1 ]; then | |
exho "USAGE: $0 PID" >&2 | |
exit 1 | |
fi | |
PID=$1 | |
touch /tmp/stdout.$PID | |
&& echo "/tmp/stdout.$PID" | |
touch /tmp/stderr.$PID | |
&& echo "/tmp/stderr.$PID" | |
#reopen files descriptors to tmp files | |
gdb -nh \ | |
-p $PID \ | |
-batch \ | |
-ex 'call dup2(open("/tmp/stdout.'$PID'", 1), 1)' \ | |
-ex 'call dup2(open("/tmp/stderr.'$PID'", 1), 2)' \ | |
-ex detach > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment