美文网首页
linux下查看多线程

linux下查看多线程

作者: shuff1e | 来源:发表于2018-03-31 11:16 被阅读7次
The four threads will have the same PID but only when viewed from above. What you (as a user) call a PID is not what the kernel (looking from below) calls a PID.
In the kernel, each thread has it's own ID, called a PID (although it would possibly make more sense to call this a TID, or thread ID) and they also have a TGID (thread group ID) which is the PID of the thread that started the whole process.
Simplistically, when a new process is created, it appears as a thread where both the PID and TGID are the same (new) number.
When a thread starts another thread, that started thread gets its own PID (so the scheduler can schedule it independently) but it inherits the TGID from the original thread.
That way, the kernel can happily schedule threads independent of what process they belong to, while processes (thread group IDs) are reported to you.

关于线程继承关系图如下:

               USER VIEW
 <-- PID 43 --> <----------------- PID 42 ----------------->
                     +---------+
                     | process |
                    _| pid=42  |_
                  _/ | tgid=42 | \_ (new thread) _
       _ (fork) _/   +---------+                  \
      /                                        +---------+
+---------+                                    | process |
| process |                                    | pid=44  |
| pid=43  |                                    | tgid=42 |
| tgid=43 |                                    +---------+
+---------+
 <-- PID 43 --> <--------- PID 42 --------> <--- PID 44 --->
                     KERNEL VIEW

相关文章

  • linux下查看多线程

    http://smilejay.com/2012/06/linux_view_threads/ https://b...

  • 多线程编程

    多线程编程之Linux环境下的多线程(一)多线程编程之Linux环境下的多线程(二)多线程编程之Linux环境下的...

  • Linux多线程编程实例解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件...

  • Linux C语言多线程编程实例解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件...

  • Linux多线程编程实例解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件...

  • Linux之多线程编程实例

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件...

  • Linux多线程实例解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件...

  • Linux多线程编程实例解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件...

  • 树莓派查看opencv版本

    1.查看linux下的opencv安装库: 2.查看linux下的opencv安装版本: 3.查看linux下的o...

  • 学习小组Day2笔记--lqp

    linux系统 稳定、效率、免费、开源、安全、多线程多用户 linux基础命令 登录服务器 显示和查看当前目录,创...

网友评论

      本文标题:linux下查看多线程

      本文链接:https://www.haomeiwen.com/subject/ohrgcftx.html