为了能快速地将pid转为process descriptor的对应指针,linux维护了4个hash table,采用4个hash table的原因是因为对于每个进程,有4种不同意义的pid:
1.pid (进程的pid)
2.tgid ( pid of thread group leader process)
3.pgid ( pid of the group leader process)
4.sid ( sid pid of the session leader process)
hash table 所采用的hash function,代码如下:
unsigned long hash=val*0x9e370001UL;
return hash >> (32 - bits)
其中0x9e370001UL十进制为2654404609,来源于离pow(2,32)的黄金分割最近的素数,也就是离pow(2,32)*(pow(5,1/2)-1)/2最近的素数。
hash table采用的是list的方式来消除冲突,每个list项是一个process descriptor 结构。
2009/01/15 四
pid to process descriptor
最新推荐文章于 2019-08-16 20:52:48 发布