Spawn process from multithreaded application

后端 未结 2 1218
死守一世寂寞
死守一世寂寞 2021-02-04 10:29

I have a situation where I need to spawn a helper process from within a very large, multithreaded application, which I do not have complete control over.

Right now I\'m

2条回答
  •  无人及你
    2021-02-04 11:23

    Calling fork should be safe if you limit yourself to "raw" system calls (syscall(SYS_fork), syscalll(SYS_execve, ...), etc.). Call into any glibc routine, and you'll be in a lot of trouble.

    Calling vfork is not at all what you want: only the thread that called vfork is suspended, and other threads will continue to run (and in the same address space as the vforked child). This is very likely to complicate your life.

    Calling clone directly is possible, but exceedingly tricky. We have an implementation that allows for safe forking of child processes from multithreaded apps (unfortunately not open source). That code is very tricky, and surprisingly long.

提交回复
热议问题