I'd like to dup a file descriptor running in an unrelated process on Linux. I know about sendmsg(2) and
SCM_RIGHTS (e.g. https://stackoverflow.com/questions/4489433/sending-file-descriptor-over-unix-domain-socket-and-select) , but that works only if the other process is cooperating. I need a solution which doesn't need active cooperation from the other process. I also know that I could create the file descriptor first, keep a copy, and then create the other process, but I need a solution in which the other process creates its own file descriptor.
I can see the file descriptor:
$ ls -l /proc/13115/fd/3 lrwx------ 1 pts pts 64 2013-05-04 13:15 /proc/13115/fd/3 -> socket:
open("/proc/13115/fd/3", O_RDWR) executed in another process returns the error No such device or address. Is there something else that would work? Probably with ptrace?