BASH: How to recover a output stdin and stderr process disowned with disown or nohup
Wow strace is great.
I discovered it today and its fantastic.
it's a process sniffer... a GREAT hacking tool... you can see all communication between libraries and the application... GREAT GREAT GREAT!
but in practical world only one bit for now:
When you forgot to redirect a output of a important process at start, that can not be stoped or restarted for now, but you need to read the output that is redirected to /dev/null, how do you do ?
strace can do this trick.
Sample:
this will create a background process with no output, but we have now the PID in var $PID, then you can sniffer the stdout and stderr with this trick:
I discovered it today and its fantastic.
it's a process sniffer... a GREAT hacking tool... you can see all communication between libraries and the application... GREAT GREAT GREAT!
but in practical world only one bit for now:
When you forgot to redirect a output of a important process at start, that can not be stoped or restarted for now, but you need to read the output that is redirected to /dev/null, how do you do ?
strace can do this trick.
strace -e write=1,2 -p $PID 2>&1 | sed -un "/^ |/p" | sed -ue "s/^.\{9\}\(.\{50\}\).\+/\1/g" -e 's/ //g' | xxd -r -p;
Sample:
{ i=0; while sleep 1; do echo -e "writing a long line to stdout 1 [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] 2 [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] 3 [CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC] \nline2 == var i=$((i ))";done; } > /dev/null & PID=$!
this will create a background process with no output, but we have now the PID in var $PID, then you can sniffer the stdout and stderr with this trick:
strace -e write=1,2 -p $PID 2>&1 | sed -un "/^ |/p" | sed -ue "s/^.\{9\}\(.\{50\}\).\+/\1/g" -e 's/ //g' | xxd -r -p;
Comentários