I need to send SIGABRT to all children of my process in a signal handler of this process.
in this answer and in this answer and in some others, it is suggested to go through all processes' directories in /proc. UPD: I have just discovered even a better /proc way.
For this, one needs opendir, readdir, closedir, etc. But they are not async-signal-safe. In this answer, it is explained that this is because "opendir() calls malloc(), so you can't run it from within the handler". As far as I understand, the problem is that malloc() can be called by the same thread two times: in the handler and in the working code of the thread. So you get a deadlock, as it happens in this question: malloc inside linux signal handler cause deadlock.
To solve a similar problem Is there an async-signal-safe way of reading a directory listing on Linux?, it is suggested:
If you know in advance which directory you need to read, you could call opendir() outside the signal handler (opendir() calls malloc(), so you can't run it from within the handler) and keep the DIR* in a static variable somewhere.
But in my case I don't know the directories beforehand, as I don’t know which children processes with which pids will exist at the point when the signal handler is called.
Is there any way to safely find and kill all the children processes of my process in its signal handler? Thank you for attention.