Nice. Thanks for that. The only addendum I would make is that the second parameter to open specifies to open the file as writable. Usually the constant is O_WRONLY, but it wasn't working for me in GDB.
Wow, I get that the gdb stuff is the real clever trickery, but 'disown' is the most valuable thing I got from that. I knew about nohup, but I didn't know about disown.
Disown is actually implemented by bash (or your shell of choice). From my understanding, it just stops the HUP propagating down to that child. There might be a more shell-agnostic way to assign the parent process id too.
Alternatively, if you know you're going to want to do this beforehand, check out the 'nohup' command. It does basically the same thing with any command it's given.
Actually, it's not meant as an alternative, but when you forgot to use nohup or stderr/stdout redirect, ie. redirect output from an already running process.