Last active
August 25, 2022 12:00
-
-
Save izabera/d9135699cf8fd50a4c1b8673f179305d to your computer and use it in GitHub Desktop.
Dump what an arbitrary linux process writes to some fd
This file contains 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
#!/bin/sh -e | |
target=${1?usage: $0 pid [fd]} | |
fd=${2-1} | |
fifo=fifo.$$ | |
log=log.$$ | |
mkfifo $fifo | |
echo writing to $log | |
tee $log <$fifo >/proc/$target/fd/$fd & | |
gdb -p $target --batch-silent -ex "call (int) open(\"$fifo\", 1)" -ex "call (int) dup2(\$1, $fd)" -ex "call (int) close(\$1)" | |
rm $fifo | |
tail -f $log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment