Re:The history of sending signals to Unix process groups
by Arnavion on Tuesday September 06, 2022 @01:07PM
(#32739989)
Might be easier to freeze the cgroup, send the signals, then unfreeze. Only danger there is that it needs to not be reentrant.
Edit: Indeed both your and my methods were proposed to systemd: https://github.com/systemd/systemd/issues/13101 It's just waiting for someone to implement it.
There may be a better way to do this, but one way might be to open() /proc/<PID> and use the resulting FD to both to check /proc/<PID>/cgroup (using openat(FD, "cgroup", O_RDONLY|O_NOCTTY)) and then use the same FD as a PIDFD when calling pidfd_send_signal().
ISTM that systemd should use this method if its current method is just looping over PIDs.