prctl线程命名函数

prctl可以给线程设置名字,便于程序调试。

/*
 * prctlT.cpp
 *
 *  Created on: 2021年5月11日
 *      Author: 
 */
#include <stdio.h>
#include <pthread.h>
#include <sys/prctl.h>
#include <unistd.h>
void* prctlT(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, prctlT, NULL);
    pthread_join(tid, NULL);
    return 0;
}

查看测试进程号:
# ps -ef | grep "xpt"
查看测试进程号的任务线程
# ps -L -p 24574
展示命名为“xx”线程的任务状态
# cd /proc/24574/task/24576
cat stat
# cat status

VmSize代表进程现在正在占用的内存

这个值与pmap pid的值基本一致,如果略有不同,可能是内存裂缝所造成的

posted @ 2021-05-18 11:32  PKICA  阅读(183)  评论(0)    收藏  举报