是否存在Windows从不用于processID的特殊值

Are there special values Windows never uses for a processID?

本文关键字:processID 用于 存在 Windows 是否      更新时间:2023-10-16

在一次代码审查中,我发现原来的程序员认为他的程序永远不会得到1010(一千零十)PID。

因此,对PID 1010进行了硬编码测试。

  • 这是安全代码吗
  • 这是windows从不使用的值吗

谢谢。

任何程序都无法获得1010(一千零十)PID。所有PID(和所有内核句柄)将是4的倍数,因为其值的两个低位将是0

ntdef.h 中提取

//
// Low order two bits of a handle are ignored by the system and available
// for use by application code as tag bits.  The remaining bits are opaque
// and used to store a serial number and table index.
//