我在包含libc
libuClibc-0.9.30.1.so(1)的 linux上获得了与本书相同的结果。
root@OpenWrt:~# ./testmain thread pid is 1151child thread pid is 1153
我试图用包含来自ubuntu的libc的linux运行该程序
libc6(2)
$ ./testmain thread pid is 2609child thread pid is 2609
libc (1) 使用
linuxthreadspthread的实现
和libc (2) 使用
NPTL(“本地posix线程库”)执行pthread
根据linuxthreads
FAQ(在J.3中回答):
每个线程实际上都是具有不同PID的不同进程,并且发送到线程PID的信号只能由该线程处理
因此,在使用
linuxthreads实现的旧libc中,每个线程都有其不同的PID
在使用
NPTL实现的新libc版本中,所有线程都具有与主进程相同的PID。
该
NPTL是由红帽团队开发。并且根据redhat
NPTL文档:在
NPTL实现中解决的问题之一是:
(第5章:现有实施中的问题)
每个具有不同进程ID的线程都会导致与其他POSIX线程实现的兼容性问题。这部分是有争议的,因为信号不能很好地使用,但仍然很明显
这可以解释您的问题。
您正在使用新的libc版本,其中包含
NPTLpthread 的(“ Native posix线程库”)实现
本书使用的旧版libc包含
linuxthreadspthread的实现



