Comment by londons_explore

4 years ago

One other option is to fork all the threads too.

Since you probably don't know what all the other threads in your process are up to, your only option is to attach a debugger to all of them, halt them all, and copy all their state into brand new threads in the child process.

Do it all correctly and you end up with a multi-threaded-fork.

You still need to fix up signal handlers, interrupted syscalls, various notification API's that no longer work, memory mapped temp files used for IPC, pipes and sockets, and a bunch of other things.

But a fork of a complex process is possible. It just isn't easy.