Thread on Linux
Linux 本身沒有 thread 的概念,它把 process 跟 thread 都視為 Task。
fork()
用來生 child process,生出來的是概念上的 process。
而 clone()
可以生出跟 parent process 共用 memory space、file descriptor 的 table、signal handler 的 table 等東西的 child process,也就是概念上的 thread。Linux 用 clone()
實作 thread 概念。
clone()
有 glibc 包過的:
1 |
|
也有純 system call:
1 | long clone(unsigned long flags, void *child_stack, |