2
votes

The Linux kernel uses struct pid to represent PID in kernel space.The C code is below.

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

I can not really understand why the member tasks can represent "the lists of tasks".Since task_struct is the kernel internal representation of task,and one task only uses one task_struct.Why can more than one task share a "struct pid"?

1

1 Answers

5
votes

Because more than one task can be part of the same process. Consider, for example, a multi-threaded process using a 1-to-1 threading library like NPTL. It has a single process ID, is a single process, but consists of multiple entities scheduled by the kernel.