Search code examples
linuxsystemd

How can a program detect if it is running as a systemd daemon?


Is there any way to detect in a program that it is run by systemd as a daemon?

systemd API

sd_booted()

is used to detected if the whole system is booted by systemd, but says nothing about the program itself.

Thanks


Solution

  • Get the parent process id and see whether that process is systemd.