Linux kernel ';结构pid';在Linux/include/Linux/pid.h中定义?
我试图更好地理解内核如何实现pid名称空间。 正在使用的基本结构之一是Linux kernel ';结构pid';在Linux/include/Linux/pid.h中定义?,linux-kernel,kernel,pid,linux-namespaces,Linux Kernel,Kernel,Pid,Linux Namespaces,我试图更好地理解内核如何实现pid名称空间。 正在使用的基本结构之一是struct pid: struct pid { atomic_t count; unsigned int level; /* lists of tasks that use this pid */ struct hlist_head tasks[PIDTYPE_MAX]; struct rcu_head rcu; struct upid numbers
struct pid
:
struct pid {
atomic_t count;
unsigned int level;
/* lists of tasks that use this pid */
struct hlist_head tasks[PIDTYPE_MAX];
struct rcu_head rcu;
struct upid numbers[1]; }
现在,据我所知,numbers数组跟踪不同pid名称空间中不同pid的进程
我不明白的是任务
成员的目的。
这里写着:
..“此结构包含ID值,即具有此ID的任务列表…”
因此,我从中了解到,相同的pid在两个进程/任务之间是共享的。
现在,不同的进程/线程可以共享相同的tpid/gpid,但不能共享相同的pid!
那么,为什么会有具有相同PID的任务列表呢?我错过了什么
谢谢结构
pid
是内核的进程标识符的内部概念。
它可以识别进程、线程以及会话或进程组。这就是为什么有一个任务列表
内核代码中解释了这是以下两者之间的折衷:
- 仅存储
,不保证流程已识别 是您想要的,因为PID是以循环方式重用的pid\t
- 为进程的每个线程存储指针,这会导致表太大
pid.tasks[PIDTYPE\u pid]指向。
。任务不共享PID,但它们可以共享PGID
和SID
。为了实现统一性和代码共享,它们都位于同一阵列上。