Linux上的一个资源提到通过克隆系统调用来实现p线程创建,而其他基于unix的平台(后者以其他方式实现相同)。
这意味着在linux下,使用pthread_create从同一个进程创建的两个线程将具有不同的父进程ids。
$ ./a.out
new thread: pid 6628 tid 1026 (0x402)
main thread: pid 6626 tid 1024 (0x400)
问题
虽然克隆系统调用创建了一个子进程,该进程可以共享父进程执行上下文的可配置量(例如文件描述符和内存),但在我看来,在所有实现中,这可能不是最有效的。在Linux下,对于从pthread_c
我正在Linux上编写多线程程序,希望在线程中创建一个进程,而不结束其他线程。我查看了fork/exec,但是在linux状态的第3p节中的exec手册页中:
A call to any exec function from a process with more than one thread
shall result in all threads being terminated and the new executable
image being loaded and executed. No destructor functions shall be