Skip to main content
Removed unnecessary "success" message; improved punctuation and wording.
Source Link

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:

$ ps -eaf|grep [u]pstart'[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 
$ ps -eaf|grep [s]ystemd'[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 what the name of the process is that's PID #1 can also potentially shed potential light on which init system is being used. On Fedora 19 (which uses systemd, for example:

$ (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 ... ps call successful 

If you interrogate the init executable, you can get some info from it as well. Simply parsing the --version output. For example:

NOTE: The fact that init is not in its standard location is a bit of a hint/tell. It's always located on sysvinit systems in /sbin/init on sysvinit systems.

So there doesn't appear to be anyoneany 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.

Looking at the output from a couple of ps commands that can detect the various versions of systemd & upstart could be crafted like so:

$ 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 
$ 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 what the name of the process is that's PID #1 can also shed potential light on which init system is being used. On Fedora 19 (which uses systemd, for example:

$ (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 ... ps call successful 

If you interrogate the init executable you can get some info from it as well. Simply parsing the --version output. For example:

NOTE: The fact that init is not in its standard location is a bit of a hint/tell. It's always located on sysvinit systems in /sbin/init.

So there doesn't appear to be anyone 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.

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:

$ 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 
$ 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:

$ (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 

If you interrogate the init executable, you can get some info from it as well. Simply parsing the --version output. For example:

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.

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.

essentially limit the output of ps to those processes with init as parent; the names of some will most likely reveal which init system is used
Source Link
icarus
  • 19.1k
  • 1
  • 43
  • 57
$ (ps -eo "ppid,pid,pgid,args" 2>/dev/null || echo "ps call error") \ | grepawk -E'NR==1 '^[[:space:]]{0,}\b(PPID|ppid|ps|0|1)\b(.){0,}'|| $1==1' | less PPID  PID  PGID COMMAND 0 1 1 /sbin/init splash 0 2 0 [kthreadd] 1  228 228 /lib/systemd/systemd-journald 1 263 263 /lib/systemd/systemd-udevd 1  503 503 /lib/systemd/systemd-timesyncd ... ps call successful 
$ (ps -eo "ppid,pid,pgid,args" 2>/dev/null || echo "ps call error") \ | grep -E '^[[:space:]]{0,}\b(PPID|ppid|ps|0|1)\b(.){0,}' | less PPID  PID  PGID COMMAND 0 1 1 /sbin/init splash 0 2 0 [kthreadd] 1  228 228 /lib/systemd/systemd-journald 1 263 263 /lib/systemd/systemd-udevd 1  503 503 /lib/systemd/systemd-timesyncd ... ps call successful 
$ (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 ... ps call successful 
essentially limit the output of ps to those processes with init as parent; the names of some will most likely reveal which init system is used
Source Link

generic

$ (ps -eo "ppid,pid,pgid,args" 2>/dev/null || echo "ps call error") \ | grep -E '^[[:space:]]{0,}\b(PPID|ppid|ps|0|1)\b(.){0,}' | less PPID PID PGID COMMAND 0 1 1 /sbin/init splash 0 2 0 [kthreadd] 1 228 228 /lib/systemd/systemd-journald 1 263 263 /lib/systemd/systemd-udevd 1 503 503 /lib/systemd/systemd-timesyncd ... ps call successful 

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.

generic

$ (ps -eo "ppid,pid,pgid,args" 2>/dev/null || echo "ps call error") \ | grep -E '^[[:space:]]{0,}\b(PPID|ppid|ps|0|1)\b(.){0,}' | less PPID PID PGID COMMAND 0 1 1 /sbin/init splash 0 2 0 [kthreadd] 1 228 228 /lib/systemd/systemd-journald 1 263 263 /lib/systemd/systemd-udevd 1 503 503 /lib/systemd/systemd-timesyncd ... ps call successful 

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.

Post Merged (destination) from unix.stackexchange.com/questions/114613/…
added 970 characters in body
Source Link
slm
  • 380.2k
  • 127
  • 793
  • 897
Loading
Source Link
slm
  • 380.2k
  • 127
  • 793
  • 897
Loading