多线程进程的线程ID可以与另一个正在运行的进程的进程ID相同吗? [英] Can the thread ID of a multithreaded process be the same as the process ID of another running process?

查看:875
本文介绍了多线程进程的线程ID可以与另一个正在运行的进程的进程ID相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种在多进程环境中唯一标识线程的方法.我有一台服务器,它跟踪连接到它的不同进程,其中有些是多线程的,有些不是.为了从多线程连接中识别线程,我使用线程ID作为唯一标识符(在任何给定时间最多连接1个多线程进程).我的问题是:这些线程之一的线程ID是否可能与系统上运行的另一个进程的进程ID相同?

I'm trying to find a way to uniquely identify threads in a multi-process environment. I have a server that keeps track of the different processes connecting to it, some of which are multi-threaded and some of which are not. To identify the threads from multi-threaded connections I'm using the thread ID as a unique identifier (there will be a maximum of 1 multi-threaded process connected at any given time). My question is: is it possible the the thread ID of one of these threads could be the same as the process ID of another processes running on the system?

提前感谢您的帮助!

推荐答案

TID(由sys_gettid()系统调用返回)在系统 1 上的所有线程中都是唯一的.单线程进程的PID和TID相等.这意味着TID绝不会与其他进程的PID发生冲突.

The TID (as returned by the sys_gettid() system call) is unique across all threads on the system1, and for a single-threaded process the PID and TID are equal. This means that a TID will never clash with a PID from another process.


1.需要注意的是,如果使用PID名称空间,则TID和PID仅在同一PID名称空间内是唯一的.

这篇关于多线程进程的线程ID可以与另一个正在运行的进程的进程ID相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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