from: http://blog.youkuaiyun.com/dahailantian1/article/details/5950824,感谢!
# include < stdio. h>
# include < pthread. h>
# include < sys/ prctl. h>
void * tmain( void * arg )
{
char name[ 32] ;
prctl( PR_SET_NAME, ( unsigned long ) "xx" ) ;
prctl( PR_GET_NAME, ( unsigned long ) name) ;
printf ( "%s/n" , name) ;
while ( 1)
sleep ( 1) ;
}
int main( void )
{
pthread_t tid;
pthread_create ( & tid, NULL , tmain, NULL ) ;
pthread_join ( tid, NULL ) ;
return 0;
}
本文介绍如何在C++中使用prctl函数为线程设置名称,通过代码实例展示了设置和获取线程名称的过程。
2510

被折叠的 条评论
为什么被折叠?



