close
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <sys/syscall.h> void child(void){ pid_t tid = (pid_t) syscall (SYS_gettid); printf("i am child thread , pid = %d\n",tid); } int main( int argc, char **argv){ int child_thread = 0; pthread_t id; pid_t main_thread = (pid_t) syscall (SYS_gettid); printf("main thread pid %d\n",main_thread); child_thread = pthread_create( &id, NULL,(void *) child,NULL); if(child_thread != 0){ printf ("Create pthread error!\n"); exit (1); } pthread_join( id, NULL); return 0; } |
remeber Makefile shall link library of thread
all:tpid tar=tpid obj=tpid.o src=tpid.c ${tar}:${obj} cc -o $@ $^ -lpthread ${obj}:${src} cc -c $@ $^ clean: rm -rf *.o tpid |
F.Y.I
全站熱搜