• 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的值基本一致,如果略有不同,可能是内存裂缝所造成的

  • 相关阅读:
    spring杂谈
    mysql
    java集合
    java
    mysql数据库面试题
    replace替换
    移动端拨打电话
    react 获取自定义属性、value等值
    react 框架 安装与梳理
    h5在ios端 input/textarea 输入不了
  • 原文地址:https://www.cnblogs.com/guxuanqing/p/14780245.html
Copyright © 2020-2023  润新知