As soon as the process has fork(2) ed, the child and parent processes do not share the file descriptor tables, so operations in one do not affect the others. The Linux system call clone(2) allows processes to share a file descriptor table using CLONE_FILES , and file system information (file system root, current working directory, umask) can be shared with CLONE_NS . Using clone(2) may be too big to re-record for your purposes - and because it's unusual, working with it can be annoying.
Another approach proposed by bmargulies is to create a part of the "error server" of the parent process, which tells clients for which the connect(2) port is to read the error information. If you adhere to TCP, it will work across networks, but will be open to everyone without any authentication or authorization code. If you use unix(7) sockets, you can use SCM_CREDENTIALS messages to verify the user, group, and pid of the connection process.
You can also create a new pipe(7) using the pipe(2) system call for each child before fork(2) and simply drop the filedescriptors if the child does not want to receive debugging information.
If you use a unix(7) socket to provide parent-child communication, you can use the SCM_RIGHTS message to send the filedescriptor file from one process to another - you can either pass the parent address a pipe(7) or socket(7) for reading or to send the parent element a pipe(7) or socket(7) for writing.
source share