EDIT: Note that I'm talking only about PID 1 because I can't english and thought that you want to check up on your primary init process. Change that to the unit you're interested in. I'm sure systemd will spit PID out for you somehow. Or if not,
ps ax |grep [commandname] will do it. You'll likely need to adjust the time difference between uptime and process elapsed time as well, just add a
+3 or whatever to bc line./EDIT
I'm not using systemd so take this with a grain of salt. Init-system agnostic way would be to compare the start time of the process you're interested in and system uptime. You can get those with
ps -o etimes [PID]. Traditionally, PID 1 is reserved for init process but I don't know if systemd adheres to it. Check with
ps 1 if it's indeed the process you're interested in and adjust if not. You can get system uptime in seconds (among others) with
cat /proc/uptime |cut -d "." -f 1. Delimiter for
cut is dot since
ps drops the decimals as well.
compare them with bc or your favorite way. Commandline example could be:
echo $(cut -d "." -f 1 /proc/uptime)"-"$(ps -o etimes [PID] |tail -n 1 |tr -d ' \t')|bc Expected output is 0 if the process is started on boot time. You can check if it matches to your findings. For shell scripts, I'd run it thru if/then tests and accept maybe +-3 seconds as boot time. One second at least. Otherwise you could get occasionally a non-zero answer if their uptimes differ even a small fraction of a second which could lead to hard to debug errors.