复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <stdio.h> #include <pthread.h> #include <sys/prctl.h> void* tmain(void * arg) { printf("tmainn") ; char name[ 32] ; prctl(PR_SET_NAME, (unsigned long) "thread_name" ) ; prctl(PR_GET_NAME, (unsigned long) name) ; printf("%sn", name) ; while (1) sleep (1) ; } //linux c用prctl给线程命名 // ps -L -p 3105 int main(void) { printf("pid=%dn",getpid()) ; // 设置可ptrace prctl(PR_SET_DUMPABLE, 1, 0, 0, 0); pthread_t tid; pthread_create ( & tid, NULL , tmain, NULL ) ; pthread_join ( tid, NULL ) ; return 0; }
最后
以上就是魁梧雪碧最近收集整理的关于linux c用prctl给线程命名的全部内容,更多相关linux内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复