Is it possible to reliable tell for a given Linux process if it was launched or is still supervised by an init.d script, Upstart or systemd ?
Asked
Active
Viewed 2,454 times
1 Answers
2
With systemd, you can find which systemd service a process belongs to by looking at the cgroup it is in.
For example:
$ ps -eo pid,comm,cgroup | grep dhclient
6476 dhclient 8:devices:/system.slice NetworkManager.service,1:name=systemd:/system.slice/NetworkManager.service
will tell you that the dhclient process is part of the NetworkManager.service, and is thus managed by systemd.
Whereas:
$ ps -eo pid,comm,cgroup | grep firefox
3302 firefox 8:devices:/user.slice,1:name=systemd:/user.slice/user-1000.slice/session-c2.scope
shows that this Firefox process is part of the session launched by the user with the UID 1000.
Processes launched by initscripts or Upstart jobs are indistinguishable from other manually launched background processes.
Timothée Ravier
- 486