the simplest way is to use busctl as

aleivag@algx:~$ busctl call org.freedesktop.systemd1
/org/freedesktop/systemd1 org.freedesktop.systemd1.Manager GetUnitByPID u
28729
o "/org/freedesktop/systemd1/unit/nginx_2eservice"

from that you are a  awk away of what you want. if you want to get clever
you can always do:

aleivag@algx:~$ busctl call org.freedesktop.systemd1
/org/freedesktop/systemd1 org.freedesktop.systemd1.Manager GetUnitByPID u
28729 | awk '{print $2}' | xargs -i busctl get-property
org.freedesktop.systemd1 {} org.freedesktop.systemd1.Unit Id

s "nginx.service"

But depending on what you want, if you are not bound to use a shell, you
can try using sd-bus.h in you code.



Alvaro Leiva

On Wed, Dec 20, 2017 at 9:48 PM, Kevin Hsu <[email protected]> wrote:

> Hi folks,
>
> I am looking for a good way to backtrace systemd service by a process id.
> The "systemctl status <pid>" command is available to do the magic. It will
> show a full status of the service that creates the
> pid. But this command gives too many details. The only thing I need is the
> service unit name. Is there any simple way instead of parsing results from
> "systemctl status" ?
>
> For example like
>
> > systemctl service-get 5566
> > nginx.service
>
>
> Thanks,
> Kevin Hsu
>
> _______________________________________________
> systemd-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
>
_______________________________________________
systemd-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to