
Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
As Linux users, we’re familiar with process identifiers (PID). PID is the operating system’s unique identifier for active programs that are running. A simple command to view the running processes shows that the init process is the owner of PID 1. So, the burning question is: Which process has PID 0? In this tutorial, we’ll review the Linux command to check running processes, what the PID 0 is, and the actual process that has PID 0.
There are a number of commands to check the running process in Linux. One of these is the ps command:
$ ps -eaf
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Feb25 ? 00:00:05 /sbin/init splash
root 2 0 0 Feb25 ? 00:00:00 [kthreadd]
root 3 2 0 Feb25 ? 00:00:00 [rcu_gp]
root 4 2 0 Feb25 ? 00:00:00 [rcu_par_gp]
root 9 2 0 Feb25 ? 00:00:00 [mm_percpu_wq]
root 10 2 0 Feb25 ? 00:00:00 [rcu_tasks_rude_]
The ps command displays the current active running processes. From the output above, we can see that the /sbin/init splash process has PID 1, the kthreadd process has PID 2, and so on.
We pass the -eaf options into the ps command to display all the processes on the system as a list. The ea option displays all processes while the f stands for full listing. The ps man page contains other possible arguments that we can use with the ps command.
We observe from the output above that each PID has a corresponding PPID. For instance, /sbin/init splash has PPID 0. PPID stands for Parent Process ID. In Linux systems, A parent process ID is always assigned to every process ID. It tells us which process started a particular process. Therefore, the PPID value of 0 for the init process indicates that the init process has no parent.
Sometimes, in system design, a zero input to the actuator corresponds to an off state or position. However, when we insert a 0 PID into a PID controller, it corresponds to doing nothing. No error signal would cause any correction. However, zero is not very useful as a PID in a controller, but technically, it’s valid. Hence, the PID 0 is often referred to as an idle process.
The process with PID 0 is responsible for paging, and this process is always referred to as the swapper or sched process. This process is a part of the kernel and is not a regular user-mode process. The init process owns PID 1 and is solely 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 that the kernel invoked. Furthermore, more recent Unix systems typically have additional kernel components visible as “processes”. In these systems, PID 1 is actively reserved for the init process to maintain consistency with older systems.
In this tutorial, we’ve established that the process that has PID 0 is not a user process but the process that the kernel uses for paging. In other words, it’s the swapper or sched process, which helps the operating system store and retrieve data from a secondary storage device.