Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Not much to put here in the body, the question is self explanatory.

share|improve this question
15  
pid 0 has a special meaning for the kill(2) system call where it means myself and for waitpid(2) where it means any process in my process group at least. Not to mention that fork() returning 0 means that we're in the child. –  Stephane Chazelas Nov 19 '13 at 13:33
1  
you should post this as an answer –  Koren Nov 19 '13 at 13:37
3  
Zero causes flags to be automatically set on most CPU's status registers when it is loaded in a register, enabling a branch to taken on it without specifically comparing/testing for it. Therefore it's very much used as a "sentinel" value, i.e. a value that means "invalid", "end of data", or "special case" here. So even though computers start counting at 0, there will be many cases where 1 is the first valid value for the application or data structure in question. –  ultrasawblade Nov 19 '13 at 16:02
4  
A side note: Computers don't start counting at zero. Many programming languages and I believe all machine languages use offsets where others (and most humans) use indexes but, no matter what, counting is counting. An array with two elements has two elements (count them), no matter whether your language refers to them by offset or by index. –  jthill Nov 19 '13 at 20:36
    
this is likely a case of opposing underlying paradigms of programming: the programmer's gravitation towards special flag values (zero, negative one) trumps the lesser pull of a proclivity for zero-based numbering systems. –  michael_n Nov 20 '13 at 6:13
show 1 more comment

3 Answers

up vote 23 down vote accepted

Processes need to have a parent (PPID). The kernel, despite not being a real process, is nevertheless handcrafting some real processes like at least init, and is giving itself the process ID 0. Depending on the OS it might or might not be displayed as a process in ps output but is always displayed as a PPID:

eg on Linux:

$ ps -ef|head
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 09:09 ?        00:00:00 /sbin/init
root         2     0  0 09:09 ?        00:00:00 [kthreadd]
root         3     2  0 09:09 ?        00:00:00 [ksoftirqd/0]
...

on Solaris:

$ ps -ef|head
     UID   PID  PPID   C    STIME TTY         TIME CMD
    root     0     0   0   Oct 19 ?           0:01 sched
    root     5     0   0   Oct 19 ?          11:20 zpool-rpool1
    root     1     0   0   Oct 19 ?           0:13 /sbin/init
    root     2     0   0   Oct 19 ?           0:07 pageout
    root     3     0   1   Oct 19 ?         117:10 fsflush
    root   341     1   0   Oct 19 ?           0:15 /usr/lib/hal/hald --daemon=yes
    root     9     1   0   Oct 19 ?           0:59 /lib/svc/bin/svc.startd
...

Note also that pid 0 (and -1 and other negative values for that matter) have different meanings depending on what function use them like kill, fork and waitpid.

Finally, while the init process is traditionally given pid #1, this is no more the case when OS level virtualization is used like Solaris zones, as there can be more than one init running:

$ ps -ef|head
     UID   PID  PPID   C    STIME TTY         TIME CMD
    root  4733  3949   0 11:07:25 ?           0:26 /lib/svc/bin/svc.configd
    root  4731  3949   0 11:07:24 ?           0:06 /lib/svc/bin/svc.startd
    root  3949  3949   0 11:07:14 ?           0:00 zsched
  daemon  4856  3949   0 11:07:46 ?           0:00 /lib/crypto/kcfd
    root  4573  3949   0 11:07:23 ?           0:00 /usr/sbin/init
  netcfg  4790  3949   0 11:07:34 ?           0:00 /lib/inet/netcfgd
    root  4868  3949   0 11:07:48 ?           0:00 /usr/lib/pfexecd
    root  4897  3949   0 11:07:51 ?           0:00 /usr/lib/utmpd
  netadm  4980  3949   0 11:07:54 ?           0:01 /lib/inet/nwamd
share|improve this answer
add comment

There are two tasks with specially distinguished process IDs: swapper or sched has process ID 0 and is responsible for paging, like jlliagre put in the examples before, and is actually part of the kernel rather than a normal user-mode process.

Process ID 1 is usually the init process primarily responsible for starting and shutting down the system. Originally, process ID 1 was not specifically reserved for init by any technical measures: it simply had this ID as a natural consequence of being the first process invoked by the kernel. More recent Unix systems typically have additional kernel components visible as 'processes', in which case PID 1 is actively reserved for the init process to maintain consistency with older systems.

share|improve this answer
add comment

In general, 0 is often used to signify a 'null reference'. This meant that even though the 0 value exists, you might not use it because you want zero to signify a special value.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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