进程 ID 范围

进程 ID 范围

在 GNU/Linux 系统上,我只看到了正的 PID,但是当发生内核恐慌时,我看到了有关 PID=0 的进程的信息。那是什么?

在 Minix 3 上我见过带有负 PID 的进程。 Minix 是 POSIX 兼容的系统,但是POSIX 只允许正 PID。它是什么?

我应该在 C 中使用什么变量类型来保存进程 ID?

答案1

1)这是寻呼机或交换器:哪个进程的 PID 为 0?

2)从未使用过Minix,但手册上说Minix中的负pid表示内核进程。因为这实际上是内核实现的一部分,所以我不能说这是否符合 POSIX =)

3)你应该使用pid_t

如果您的目标是最大程度的可移植性,您应该阅读 POSIX,它说:

首先,getpid()函数返回pid_tpid_t定义在 types.h 中。

第二:

   ... blksize_t, pid_t, and ssize_t shall be signed integer types. ...

   The implementation shall support one or more  programming  environments
   in  which the widths of ..., pid_t, ... are no greater than the width
   of type long. The names of these  programming  environments  can  be 
   obtained using the confstr() function or the getconf utility.

所以你可以节省pid_t价值long。另请注意,在 POSIX 中,pid_t是一个整数。

相关内容