Linux当中Process与Thread的概念
来源:互联网 发布:网络翻唱歌手李洋 编辑:程序博客网 时间:2024/05/21 10:20
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) 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 its TGID from the thread that created it.
That way, the kernel can happily schedule threads independent of what process they belong to, while processes (thread group IDs) are reported to you.
The following hierarchy of threads may help:
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
You can see that starting a new process gives you a new PID and a new TGID (both set to the same value), while starting a new thread gives you a new PID while maintaining the same TGID as the thread that started it.
来源:http://stackoverflow.com/questions/9305992/linux-threads-and-process
- Linux当中Process与Thread的概念
- process与thread的关系
- process and thread android中的进程与线程概念
- process and thread android中的进程与线程概念
- 与process&thread相关的一些函数
- Android process与Thread 的问题
- Android process与Thread 的问题
- 线程 thread 与 进程 process 的区别
- Linux process vs thread
- Create Process Thread Linux
- linux中process, kernel thread, user thread的区别
- Linux 进程与信号的概念和操作 linux process and signals
- Linux process/thread in practice
- thread和process的区别
- Process 和 thread 的区别
- Process, program, thread 的区别
- Basic Linux Multi-Process & Multi-Thread Programming
- 计算机必知必会:进程process与线程thread
- 揭秘:蓝光光碟“造”太阳能电池的神奇之处
- 黑苹果安装及相关注意事项之三,准备工作
- Socket的使用实例,控制台上的编程。嗨!这里是服务端,您已连接成功!
- 提高云计算部署速度的三大关键技术
- 收集的部分C#中窗口句柄及操作
- Linux当中Process与Thread的概念
- 以淘宝之力扫社会之假?那是开玩笑
- 数据结构第二章线性表总结
- 关于浏览器端的网页性能测试
- jquery.lazyload.js源码欣赏
- 隐藏CMD窗口
- 从IC设计业看中国企业之发展
- 还是关于“委托”
- iOS开发UITableViewCell的选中时的颜色设置