当前位置: 首页 > news >正文

linux中pthread_t 的值与top -Hp中线程id值的区别

linux中pthread_t 值与top -Hp中线程id值的区别

#include <stdio.h>
#include <pthread.h>
#include <thread>void thread_func() 
{printf("child thread id=0x%x\n",pthread_self());while(1){   printf("hello world\n");}   
}int main() 
{printf("main thread id=0x%x\n",pthread_self());//设置主线程名称pthread_setname_np(pthread_self(), "MainThread");std::thread t(thread_func);//设置子线程名称pthread_setname_np(t.native_handle(), "WorkerThread");t.join();return 0;
}
[banting@localhost test]$ g++ -g --std=c++11 test84.cpp -lpthread -o test84
[banting@localhost test]$ gdb ./test84
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-100.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/banting/test/test84...done.
(gdb) b 23
Breakpoint 1 at 0x400ec0: file test84.cpp, line 23.
(gdb) r
Starting program: /home/banting/test/./test84 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
main thread id=0xf7fe2740
[New Thread 0x7ffff6fdb700 (LWP 1347067)]
child thread id=0xf6fdb700
hello world
hello world
Breakpoint 1, main () at test84.cpp:23
23		t.join();
(gdb) info threadsId   Target Id         Frame 2    Thread 0x7ffff6fdb700 (LWP 1347067) "WorkerThread" 0x00007ffff70c585d in write () at ../sysdeps/unix/syscall-template.S:81
* 1    Thread 0x7ffff7fe2740 (LWP 1347063) "MainThread" main () at test84.cpp:23
(gdb) quit
A debugging session is active.Inferior 1 [process 1347063] will be killed.Quit anyway? (y or n) y
[banting@localhost test]$
[banting@localhost test]$ top -Hp 1347063
top - 17:42:14 up 19 days, 17:18, 22 users,  load average: 0.00, 0.01, 0.05
Threads:   2 total,   0 running,   0 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 16268040 total,  2925428 free,  3114704 used, 10227908 buff/cache
KiB Swap:  8257532 total,  8254336 free,     3196 used. 12482396 avail Mem PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND 
1347063 banting   20   0   22996   1120    912 t  0.0  0.0   0:00.00 MainThread                                                                                                                          
1347067 banting   20   0   22996   1120    912 t  0.0  0.0   0:00.00 WorkerThread  

总结

  • pthread_t的值main thread id=0xf7fe2740只与gdb调试中Thread 0x7ffff7fe2740 的后4个字节对应
  • Thread 0x7ffff7fe2740 (LWP 1347063)中(LWP 1347063) 只与top -Hp 1347063打印信息的MainThread 的线程id对应
http://www.lryc.cn/news/608181.html

相关文章:

  • 知识随记-----用 Qt 打造优雅的密码输入框:添加右侧眼睛图标切换显示
  • Autosar Nm-网管报文PNC停发后无法休眠问题排查
  • Antlr4在Windows环境下的配置
  • 涉水救援机器人cad【12张】三维图+设计书明说
  • Vue 服务端渲染 Nuxt 使用详解
  • AI Agent开发学习系列 - LangGraph(6): 有多个节点的Sequential Graph(练习解答)
  • 深入理解C++中的Lazy Evaluation:延迟计算的艺术
  • LangGraph认知篇-Command函数
  • UDP通信中BIND端口号的作用解析,LOCALPORT的关系解析
  • 搜索与图论(最小生成树 二分图)
  • 【Django】-5- ORM的其他用法
  • 企业级单点登录(SSO)技术详解:从原理到安全实践
  • 前端与后端部署大冒险:Java、Go、C++三剑客
  • ARM Cortex-M异常处理高级特性详解
  • 集成电路学习:什么是HAL硬件抽象层
  • 【DL学习笔记】计算图与自动求导
  • 紧急救援!Oracle RAC节点驱逐元凶:私网Packet Reassembles Failed“包重组失败”一招救命
  • linux ssh公钥移除办法
  • MySQL PostgreSQL JDBC URL 配置允许批量操作
  • SM2国密算法的大数运算原理详解
  • 牛客 - 旋转数组的最小数字
  • 【PCL点云库:下】
  • 详解Python标准库之互联网数据处理
  • 一个物理引擎仿真器(mujoco这种)的计算流程
  • 回溯 79 单词搜索一波三折想和
  • 中科院开源HYPIR图像复原大模型:1.7秒,老照片变8K画质
  • 深入剖析Nacos:云原生架构的基石
  • JVM 02 垃圾回收
  • 【LeetCode 热题 100】(三)滑动窗口
  • file命令libmagic、python的cchardet库使用、自定义magic文件的使用