【问题标题】:I can not understand the kernel internal representation of PID我无法理解 PID 的内核内部表示
【发布时间】:2012-01-16 01:07:29
【问题描述】:

Linux内核使用struct pid来表示内核空间的PID。C代码如下。

struct pid
{
atomic_t count;
/* lists of tasks that use this pid */
struct hlist_head tasks[PIDTYPE_MAX];
int level;
struct upid numbers[1];
};

我真的不明白为什么成员任务可以表示“任务列表”。由于task_struct是任务的内核内部表示,一个任务只使用一个task_struct。为什么多个任务可以共享一个“struct pid” “?

【问题讨论】:

    标签: c linux kernel


    【解决方案1】:

    因为多个任务可以属于同一流程。例如,考虑一个使用 NPTL 等 1 对 1 线程库的多线程进程。它有一个进程ID,是一个进程,但由内核调度的多个实体组成。

    【讨论】:

    • 是的。虽然它可能只有一个“PID”,但如果您使用 -L 选项(我认为这是 Linux 上的正确选项),您仍然可以在 ps 中看到多个“轻量级进程 ID”。
    • @JohnZwinck 您可以称它们为“TID”或“任务 ID”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 2012-03-06
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    相关资源
    最近更新 更多