如何从pthread获取pid [英] How to get pid from pthread

查看:486
本文介绍了如何从pthread获取pid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在RH Linux中,每个pthread都映射到一个pid,可以在htop等工具中进行监控。但是我怎么能得到一个线程的pid呢? getpid()只返回主线程的pid。

in RH Linux, every pthread is mapping to a pid, which can be monitored in tools such as htop. but how can i get the pid of a thread? getpid() just return the pid of the main thread.

推荐答案

pthread_self();

pthread_self();

可以调用以返回ID的调用线程。

Can be called to return the ID of the calling thread.

也是PID是进程ID,线程的线程ID不是PID。在同一进程中运行的所有线程都将具有相同的PID。

Also PID is process Id, A thread has thread Id not PID. All threads running in the same process will have the same PID.

这篇关于如何从pthread获取pid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆