I'm looking for the process started in Linux which has process ID 0. I know init
has PID 1 , which is the first process in Linux, is there any process with PID 0?

- 829,060

- 721
- 2
- 8
- 10
3 Answers
From the wikipedia page titled: Process identifier:
There are two tasks with specially distinguished process IDs: swapper or sched has process ID 0 and is responsible for paging, 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.
You can see the evidence of this if you look at the parent PIDs (PPID) of init
and kthreadd
:
$ ps -eaf
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun24 ? 00:00:02 /sbin/init
root 2 0 0 Jun24 ? 00:00:00 [kthreadd]
kthreadd
is the kernel thread daemon. All kthreads are forked from this thread. You can see evidence of this if you look at other processes using ps
and seeing who their PPID is:
$ ps -eaf
root 3 2 0 Jun24 ? 00:00:57 [ksoftirqd/0]
root 4 2 0 Jun24 ? 00:01:19 [migration/0]
root 5 2 0 Jun24 ? 00:00:00 [watchdog/0]
root 15 2 0 Jun24 ? 00:01:28 [events/0]
root 19 2 0 Jun24 ? 00:00:00 [cpuset]
root 20 2 0 Jun24 ? 00:00:00 [khelper]
Notice they're all 2
.

- 369,824
-
1So if PID 0 is swapper, then what is
kswapd[0-9]*
, which on my system has PID 52 currently? It seems to also be responsible for paging. – Ruslan Jan 12 '17 at 12:35 -
1@Ruslan - if you have follow on questions please ask them on the main site, comments are not meant for this. Reference this question in your new question. – slm Jan 12 '17 at 13:43
-
well, but when we create a new process using fork child process get pid 0? – roottraveller Sep 09 '17 at 06:32
-
@roottraveller not necessarily, whatever the parents PID is where the fork occurred will be what shows up. – slm Sep 09 '17 at 12:03
-
-
@roottraveller no, when you create a new process using
fork
, the child gets a0
return value fromfork
, because fork has nothing useful to return to the child but needs to return something distinct from an actual PID. But the child itself does not have PID 0, and that zero isn't really a PID - or at least it's certainly not the PID of any actual process. – mtraceur Oct 04 '22 at 22:48
From Process Identifier wiki:
There are two tasks with specially distinguished process IDs: swapper or sched has process ID 0 and is responsible for paging, and is actually part of the kernel rather than a normal user-mode process.

- 153,898
kill
: "If pid equals 0, then sig is sent to every process in the process group of the calling process." – kenorb Jan 20 '20 at 16:58