diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
index 203fc0355d..5b5590a233 100644
--- a/man/systemd.exec.xml
+++ b/man/systemd.exec.xml
@@ -3043,6 +3043,17 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
+
+ $SYSTEMD_EXEC_PID
+
+ The PID of the unit process (e.g. process invoked by
+ ExecStart=). The child process can use this information to determine
+ whether the process is directly invoked by the service manager or indirectly as a child of
+ another process by comparing this value with the current PID (as similar to the scheme used in
+ sd_listen_fds3
+ with $LISTEN_PID and $LISTEN_FDS).
+
+
$TERM
diff --git a/src/core/execute.c b/src/core/execute.c
index b7d78f2197..29fe9f05b1 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1794,7 +1794,7 @@ static int build_environment(
assert(p);
assert(ret);
-#define N_ENV_VARS 16
+#define N_ENV_VARS 17
our_env = new0(char*, N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX);
if (!our_env)
return -ENOMEM;
@@ -1950,6 +1950,11 @@ static int build_environment(
our_env[n_env++] = x;
}
+ if (asprintf(&x, "SYSTEMD_EXEC_PID=" PID_FMT, getpid_cached()) < 0)
+ return -ENOMEM;
+
+ our_env[n_env++] = x;
+
our_env[n_env++] = NULL;
assert(n_env <= N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX);
#undef N_ENV_VARS