First of all, Here is my environment of system:
# cat /proc/version
Linux version 4.15.0-52-generic (buildd@lgw01-amd64-051) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #56-Ubuntu SMP Tue Jun 4 22:49:08 UTC 2019
# cat /etc/issue
Ubuntu 18.04.2 LTS \n \l
Refer to this Ubuntu Wiki, ubuntu has used Systemd by default since 15.04 and Systemd runs with PID 1 as /sbin/init
. However, I found the different result on my ubuntu 18.04:
# ps aux | awk '$2==1{print $0}'
root 1 0.0 0.8 159692 8784 ? Ss Oct24 0:21 /sbin/init noibrs splash
# lsof -p 1 | grep txt
systemd 1 root txt REG 252,1 1595792 927033 /lib/systemd/systemd
So, my question is that:
Why Ubuntu 18.04 use /sbin/init
instead of /lib/systemd/systemd
?
Why lsof -p 1 | grep txt
return /lib/systemd/systemd
while the process of PID 1 is /sbin/init
?
/sbin/init
is a symbolic link to /lib/systemd/systemd
Take a look at the output of stat /sbin/init
or readlink /sbin/init
This is what they mean by systemd "running as /sbin/init". The systemd binary is linked as /sbin/init
and started by that link name.
Update
To further explain the difference between the ps
and lsof
output: ps
is showing the command that started the process, while lsof
is showing which files a process has opened.
When systemd was started, it was called by /sbin/init noibrs splash
, the file system resolved the link to the file /lib/systemd/systemd
which was then read from disk and executed.