Using processes
Looking at the output from a couple of ps
commands that can detect the various versions of systemd
& upstart
, which could be crafted like so:
upstart
$ ps -eaf|grep '[u]pstart'
root 492 1 0 Jan02 ? 00:00:00 upstart-udev-bridge --daemon
root 1027 1 0 Jan02 ? 00:00:00 upstart-socket-bridge --daemon
systemd
$ ps -eaf|grep '[s]ystemd'
root 1 0 0 07:27 ? 00:00:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 20
root 343 1 0 07:28 ? 00:00:03 /usr/lib/systemd/systemd-journald
root 367 1 0 07:28 ? 00:00:00 /usr/lib/systemd/systemd-udevd
root 607 1 0 07:28 ? 00:00:00 /usr/lib/systemd/systemd-logind
dbus 615 1 0 07:28 ? 00:00:13 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
Paying attention to the name of the process that's PID #1 can also potentially shed light on which init system is being used. On Fedora 19 (which uses systemd
, for example:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 07:27 ? 00:00:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 20
Notice it isn't init
. On Ubuntu with Upstart it's still /sbin/init
.
$ ps -efa|grep init
root 1 0 0 Jan02 ? 00:00:03 /sbin/init
NOTE: But use this with a bit of caution. There isn't anything set in stone that says a particular init system being used on a given distro has to have systemd
as the PID #1.
generic
$ (ps -eo "ppid,args" 2>/dev/null || echo "ps call error") \
| awk 'NR==1 || $1==1' | less
PPID COMMAND
1 /lib/systemd/systemd-journald
1 /lib/systemd/systemd-udevd
1 /lib/systemd/systemd-timesyncd
Look at processes with ppid 1 (children of the init process). (Some of the) child process names might point to the init system in use.
The filesystem
If you interrogate the init
executable, you can get some info from it as well. Simply parsing the --version
output. For example:
upstart
$ sudo /sbin/init --version
init (upstart 1.5)
Copyright (C) 2012 Scott James Remnant, Canonical Ltd.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
systemd
$ type init
init is /usr/sbin/init
NOTE: The fact that init
is not in its standard location is a bit of a hint/tell. It's always located in /sbin/init
on sysvinit systems.
sysvinit
$ type init
init is /sbin/init
Also this:
$ sudo init --version
init: invalid option -- -
Usage: init 0123456SsQqAaBbCcUu
Conclusions
So there doesn't appear to be any one way to do it, but you could formulate a suite of checks that would pinpoint which init system you're using with a fairly high degree of confidence.
ps -p 1 -o command
(prints the path to the currentinit
). On Arch Linux and Fedora (IIRC), it's a symlink to thesystemd
binary (probably same on allsystemd
systems). Onupstart
,init --help
will print usage information, and on my box,upstart
is mentioned where it says who to email. On FreeBSD (sysV), this will return an error. There may be similar clues on other systems, but since asking this question, I've decided to just create them for all platforms and make separate packages for each one. – beatgammit Nov 24 '13 at 19:48sudo lsof -a -p 1 -d txt
may give even more exact results.ps
may print an arbitrary name, whereas withlsof
you will get the real executable path. (See my question http://unix.stackexchange.com/questions/102453/what-does-init-2-mean-in-the-command-column-of-ps ) – n611x007 Nov 24 '13 at 22:25ps -eaf|grep systemd
, ps -eaf | upstart`...accomplish what you're asking? It reads like you're asking how you'd do this from visual inspection. Am I missing it still? – slm Feb 10 '14 at 20:202014-02-10 20:08:49Z
. your comment:2014-02-10 20:18:59Z
. I think somehow cpburnz ended up talking on this -ie. someone else's- question her/his own question's duplicate flag. it seems like unfortunate to me. – n611x007 Jul 22 '15 at 14:18rpm --quiet --query systemd
. this avoids the hanky panky involved in looking for a process or pid or symlink. – Trevor Boyd Smith Jan 09 '18 at 19:12