#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 3105
int main(void)
{
printf("pid=%d\n",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给线程命名
最新推荐文章于 2023-10-07 22:10:29 发布