2

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

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

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

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.