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

此生再无相见时 提交于 2021-02-05 05:58:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!