今天寫線程,想看看 pthread_t 的實際類型是什麼,vi /usr/include/pthread.h 頭文件,最後找到 pthread_t 定義在#include <bits/pthreadtypes.h> 該頭文件中,一步一步的找能夠找出來,不過麻煩;不如用 gcc -E cfile.c -o cfile.e 預編譯,而後grep pthread_t 就能夠看到定義爲:typedef unsigned long int pthread_t; 比較好用。.net
固然須要對gcc的編譯幾個階段熟悉,gcc -${E,S,c} .. 和記住這個單詞,逃生(escape),就能夠記住。線程
[root@localhost pthread]# cat pthreadtest.c ip
#include <pthread.h>get
#include <stdio.h>it
#include <unistd.h>io
#include <stdlib.h>編譯
int * thread(void * thread)function
{class
pthread_t newthid;thread
newthid = pthread_self();
printf("new thread id is : %u \n",newthid);
}
int main(int argc,char ** argv,char **envp)
{
pthread_t thid;
if(pthread_create(&thid,NULL,(void*)thread,NULL)!=0)
{
printf("Create failed.\n");
exit(1);
}
sleep(1);
exit(0);
}
編譯記得席上 gcc cfile.c -lpthread -o pthreadtest.bin
由於不在默認搜索路徑上
[root@localhost pthread]# find / -name libpthread*
/usr/lib/libpthread_nonshared.a
/usr/lib/libpthread.so
/lib/libpthread.so.0
/lib/libpthread-2.12.so
/lib/i686/nosegneg/libpthread.so.0
/lib/i686/nosegneg/libpthread-2.12.so
----查看這個文件
[root@localhost pthread]# t=/usr/lib/libpthread.so && file $t && echo -e "\n\n"&& cat $t
/usr/lib/libpthread.so: ASCII C program text
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-i386)
GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )