[systemd-devel] How to get all PIDs in a service

Andrei Borzenkov arvidjaar at gmail.com
Thu Jun 4 09:31:52 PDT 2015


В Thu, 04 Jun 2015 10:08:52 +0200
Sébastien Luttringer <seblu at seblu.net> пишет:

> Hello,
> 
> In order to restart updated daemons on filesystems, I created a
> script[1] which lists all PID by service and look for updated files in
> /proc/$pid/maps.
> 
> To get all PIDs of a service, I use "systemctl show -p ControlGroup" to
> craft a path to the "tasks" file.
> 
> But something wrong happen with escaping with some units (e.g serial
> -getty)
> 
> This works:
> #cat /sys/fs/cgroup/systemd/$(systemctl show systemd-logind.service -p
> ControlGroup|cut -f2 -d=)/tasks
> 286
> 
> This not:
> #cat /sys/fs/cgroup/systemd/$(systemctl show serial-getty at ttyS0.service 
> -p ControlGroup|cut -f2 -d=)/tasks
> /sys/fs/cgroup/systemd/$(systemctl show  -p ControlGroup|cut -f2 -d=)
> cat: /sys/fs/cgroup/systemd//system.slice/system-serial\
> x5cx2dgetty.slice/serial-getty at ttyS0.service/tasks: No such file or
> directory
> 

It seems to work here using systemd 210 on openSUSE

bor at opensuse:~/src/systemd> cat /sys/fs/cgroup/systemd/$(systemctl show systemd-rfkill at rfkill1.service -p ControlGroup | cut -f2 -d=)/tasks

bor at opensuse:~/src/systemd> systemctl show systemd-rfkill at rfkill1.service -p ControlGroup --no-pager 
ControlGroup=/system.slice/system-systemd\x2drfkill.slice/systemd-rfkill at rfkill1.service

> What's the right way to get all pid belonging to a service? How can I
> unescape strings from systemctl?
> 

Well, you can use systemd-escape -u, but real question is why it gets
escaped twice and is it intentional.

> This is happening since a long time. I made these tests on systemd v220
> et v219.
> 
> Cheers,
> 
> [1] https://github.com/seblu/archutils/blob/master/checkservices
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150604/8b2e9922/attachment.sig>


More information about the systemd-devel mailing list