A practical technique for redirecting stderr of an already-running process using gdb. By attaching gdb to the process with `gdb -p`, you can execute arbitrary C code in the process's address space using the `compile code` command. The approach calls `dup2(open("/tmp/log", 65), 2)` to open a file and overwrite file descriptor 2 (stderr) with it. This is cleaner than strace-based approaches and leverages gdb's ability to inject and run code in a live process.

2m read timeFrom drewdevault.com
Post cover image

Sort: