问题
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
回答1:
Get the parent process id and see whether that process is systemd
.
回答2:
You could set a magic environment variable in the daemon's service file and look for this variable.
来源:https://stackoverflow.com/questions/39368185/how-can-a-program-detect-if-it-is-running-as-a-systemd-daemon