For an answer to gdb - Transferring control of ptrace to another process - Unix & Linux Stack Exchange.
To run:
[]$ gcc double-fork-A.c -o A
[]$ gcc -g double-fork-B.c -o B
[]$ ./A
Read from B: 123
No symbol table is loaded. Use the "file" command.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
0x0000123456789123 in read () from /usr/lib/libc.so.6
#5 0x0000123456789123 in main () at B.c:9
[Inferior 1 (process 123456) detached]
[]$ gcc prctl-A.c -o A
[]$ gcc -g prctl-B.c -o B
[]$ ./A # need to interrupt manually below
Read from B: 123
No symbol table is loaded. Use the "file" command.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
0x0000123456789123 in read () from /usr/lib/libc.so.6
#5 0x0000123456789123 in main () at B.c:9
[Inferior 1 (process 123456) detached]
^C