prctl()和pthread_setname_np()函数
函数原型:
#include <sys/prctl.h>
int prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);
功能:
prctl(PR_SET_NAME, “process_name”);
prctl功能取决于第一个参数(操作类型),这里使用PR_SET_NAME,即设置进程名;
第二个参数是进程名字符串,长度至多16字节;
示例:
void setPthreadName(char *name)
{
if(name != NULL)
{
(void)prctl(15, (unsigned long)name);//lname 最多16个字符
}
}
pthread.h头文件
简介
在Unix/Linux系统中,C/C++提供了pthread(POSIX线程)API。它允许我们为并发流程创建多个线程,这可以提高程序在多核处理器或上的执行速度。
想要使用pthreads库的所有功能,我们必须在.c或.c++文件中包含pthread.h头文件,在编译文件时在命令行中使用 -pthread 或 -lpthread。
c++11 创建线程的三种方法
参考资料
https://blog.csdn.net/fivedoumi/article/details/24407779
http://man7.org/linux/man-pages/man2/prctl.2.html