gpt4 book ai didi

c++ - Windows 是否有从不用于 processID 的特殊值?

转载 作者:可可西里 更新时间:2023-11-01 11:52:40 26 4
gpt4 key购买 nike

在代码审查期间,我发现最初的程序员假设他的程序永远不会获得 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.
//

关于c++ - Windows 是否有从不用于 processID 的特殊值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26551521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com