NPTLを使用していると思われるUbuntu 12.04 LTSサーバーx64(3.2カーネル)でいくつかのコードをテストしました。
私が走るとき
$ getconf GNU_LIBPTHREAD_VERSION
私は得る
NPTL 2.15
以下はテストコードです。gcc -g -Wall -pthread でコンパイルしました
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
void *func1(void *arg)
{
printf("func1:[%d]%lu\n", getpid(), pthread_self());
for(;;);
return (void *)0;
}
int main(void)
{
printf("main:[%d]%lu\n", getpid(), pthread_self());
pthread_t tid1;
pthread_create(&tid1, NULL, func1, NULL);
void *tret = NULL;
pthread_join(tid1, &tret);
return 0;
}
プログラムを実行すると、すべて予想どおりのようです。2 つのスレッドの pid が同じです。
$ ./a.out
main:[2107]139745753233152
func1:[2107]139745744897792
しかし、htop (top のようなツールで、apt-get で取得できます) では、次のように表示されます: 2 つのスレッドの pid が異なります
PID Command
2108 ./a.out
2107 ./a.out
pid 2108を強制終了すると、プロセスが強制終了されます
$ kill -9 2108
$./a.out
main:[2107]139745753233152
func1:[2107]139745744897792
Killed
そして、gdb を介してプログラムを実行すると、LWPが表示されます。
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
main:[2183]140737354069760
[New Thread 0x7ffff77fd700 (LWP 2186)]
func1:[2183]140737345738496
NPTL のスレッドは 1 つの PID を共有し、LWP はカーネル 2.6 より前の LinuxThreads 用だと思います。上記は、NPTL がまだ LWP を使用しているようです。私は正しいですか?NTPLとLWPの真相が知りたいです。
ありがとう。