[systemd-devel] Howto detect a program/service is started by systemd?

Silvio Knizek killermoehre at gmx.net
Tue Aug 5 11:09:49 UTC 2025


Am Montag, dem 30.06.2025 um 12:25 +0200 schrieb Stef Bon:

> Hi,
> 
> 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?
> 
> S. Bon

Hi,

to check if the system was booted with `systemd`, check the existence and return value of

```
systemd-notify --booted
```

See <man:systemd-notify(1)> for more information and some alternatives.

BR  
Silvio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20250805/6b93d79d/attachment.htm>


More information about the systemd-devel mailing list