Skip to content

Instantly share code, notes, and snippets.

@izabera
Last active August 25, 2022 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izabera/d9135699cf8fd50a4c1b8673f179305d to your computer and use it in GitHub Desktop.
Save izabera/d9135699cf8fd50a4c1b8673f179305d to your computer and use it in GitHub Desktop.
Dump what an arbitrary linux process writes to some fd
#!/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