On Linux, threads are implemented in terms of processes. In other words, threads are actually just fork() with most of the shared memory, not copy to write entirely. This means that when you use fork() on a stream (main or another), you end up copying all the shared memory space of all the threads and storage with the specific thread of the stream that you are calling fork() from,
Now all this sounds good, but that does not mean that it will or will work well. If you want to make a cloned process, try making a fork before starting any other threads, and then use read-only virtual memory to update the branching process with the current memory values.
So, although this might work, I just suggest testing and try to find another way first. And get ready for a lot:
Segmentation fault
source share