linux c用prctl给线程命名

来源:互联网 发布:淘宝客全店推广 编辑:程序博客网 时间:2024/05/21 04:21
#include <stdio.h> #include <pthread.h> #include <sys/prctl.h> void* tmain(void * arg) { printf("tmain\n") ;         char name[ 32] ;         prctl(PR_SET_NAME, (unsigned long) "thread_name" ) ;         prctl(PR_GET_NAME, (unsigned long) name) ;         printf("%s\n", name) ;         while (1)                 sleep (1) ; } //linux c用prctl给线程命名// ps -L -p 3105int main(void) {printf("pid=%d\n",getpid()) ; // 设置可ptraceprctl(PR_SET_DUMPABLE, 1, 0, 0, 0);pthread_t tid; pthread_create ( & tid, NULL , tmain, NULL ) ; pthread_join ( tid, NULL ) ; return 0; }

0 0
原创粉丝点击