If computers start counting at 0, why does the init process have a pid of 1
initkernelprocess
Not much to put here in the body.
Best Answer
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:
$ 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:
All the instances of Mate Terminal have the same PID because they are in fact a single process which happens to display multiple windows. Mate Terminal runs in a single process because that's the way the application is designed. When you run the command mate-terminal, it contacts the existing process and sends it an instruction to open a new window.
As of Mate Terminal 1.8.1, you can run mate-terminal --disable-factory to open a new window in a new process. Beware that this option has been removed from the Gnome version in 3.10; I don't know whether the Mate developers have decided to merge that change. See Run true multiple process instances of gnome-terminal for a similar question regarding Gnome-terminal.
Because a process that dies (crashes, presumably) soon after starting is broken, and has to be fixed. Wasting resources on it makes no sense (and the crashing process could do damage, like leaving mangled files behind).
Best Answer
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:
on Solaris:
Note also that pid
0
(and-1
and other negative values for that matter) have different meanings depending on what function use them likekill
,fork
andwaitpid
.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 oneinit
running: