我在stackoverflow上得到了答案here。它指出如果我們在Linux上運行一個包含libc libuClibc-0.9.30.1.so(1)的程序。基本上是舊版本的的libc然後線程創建將具有不同的PID如下所示
[email protected]:~# ./test
main thread pid is 1151
child thread pid is 1153
,我試圖與包含的libc從ubuntu的libc6的(2),即新的libc的版本,那麼線程一個Linux運行此程序所創建的將具有與該過程相同的PID。
$ ./test
main thread pid is 2609
child thread pid is 2609
The libc (1) use linuxthreads implementation of pthread
而且提供的libc(2)使用NPTL
( 「本地POSIX線程庫」)執行並行線程
的按照linuxthreads
FAQ(在J.3答案):
每個線程真是一個截然不同的PID過程,並且信號發送到PID的一個線程只能通過那個線程來處理
所以在舊的libc
裏面用linuxthreads
實現,每個線程都是ha s其獨特的PID
在使用NPTL
實現的新libc版本中,所有線程都具有與主進程相同的PID。
NPTL
是由redhat團隊開發的。並根據redhat NPTL document:其一這是在NPTL實現解決的問題是:
(Chapter: Problems with the Existing Implementation, page5)
Each thread having a different process ID causes compatibility problems with other POSIX thread implementations. This is in part a moot point since signals can't be used very well but is still noticeable
這說明這個問題。
我正在使用包含pthread的NPTL
(「Native posix線程庫」)實現的新libc版本。
來源
2013-10-30 19:38:44
neo
[difference-between-pid-and-tid]的可能重複(http://stackoverflow.com/questions/4517301/difference-between-pid-and-tid)。 – rodrigo
我不認爲這是http://stackoverflow.com/questions/4517301/difference-between-pid-and-tid的重複。當我們運行一個程序並創建線程時,我在這裏詢問線程和進程ID。 – neo
@mohit ::通過這個[鏈接](http://stackoverflow.com/questions/19676071/understanding-pthreads),我剛剛幾個小時前發佈。 –