3

On GNU/Linux system I have only seen positive PIDs, but when kernel panic occurred I seen info about process with PID=0. What's it?

On Minix 3 I have seen processes with negative PIDs. Minix is POSIX-compatible system, but POSIX allows only positive PIDs. What is it?

What variable type should I use in C for saving process ID?

Kolay.Ne
  • 166
hon
  • 179

1 Answers1

6

1) This is pager or swapper: Which process has PID 0?

2) Never used Minix but manual says negative pid in Minix means kernel process. As this is actually part of the kernel implementation, I can't say if that comply or not to POSIX =)

3) You should use pid_t

If your aim is maximum portability you should read POSIX and it says:

First, getpid() function returns pid_t. pid_t is defined in types.h.

Second:

   ... 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.

So you can save pid_t value in long. Also notice that by POSIX, pid_t is an integer.

gena2x
  • 2,397