[systemd-devel] Howto detect a program/service is started by systemd?
Lukasz Stelmach
l.stelmach at samsung.com
Mon Jun 30 11:05:45 UTC 2025
It was <2025-06-30 pon 12:25>, when Stef Bon wrote:
> it's important for a program to detect it has been started by systemd.
> For example it does not have to fork since it has already been forked.
>
> I've written a test script, which calls env, and there are a few
> unique environment variables which are an indication it has been
> started by systemd: SYSTEMD_EXEC_PID and INVOCATION_ID.
>
> Is it a good way to test these environment vars (to detect started by
> systemd) or is there a better way?
It seems reasonable. You may want to read systemd's daemon(7) manual
page[1] to get a bigger picture, how programs should interact with
systemd.
[1] https://www.freedesktop.org/software/systemd/man/latest/daemon.html#
--
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20250630/7dad1523/attachment.sig>
More information about the systemd-devel
mailing list