How can I reliably track the processes of a child / grandson in a POSIX system?

I have an interesting (at least to me) problem: I cannot find a way to reliably and portablely get information about the processes of grandchildren in certain cases. I have an application, AllTray , that I try to work in some strange cases, when its subprocess gives birth to a child and then dies. The task of AllTray is to attach the application to the task tray, which (as a rule) is indicated on the command line for calling AllTray (i.e. alltray xtermruns xterm and manages it in AllTray).

Most GUI programs work only under it. He sets the property _NET_WM_PIDin his window (or widget library) and all is well, because _NET_WM_PID== fork()ed child. However, in some cases (for example, at startup oowriteror software written to run under KDE, for example K3b), the child process that launches AllTray is a shell, whether it be a shell script (as is the case with OO.o) or a strange program, which itself fork()and exec()itself uses itself as the parent dies very early.

I had the idea not to retrieve my child processes in order to save the parent process ID for my grandchildren in the process table so that I could associate them with me, going through the family tree from bottom to top, However, this will not work: when my child process dies and turns in zombies, the system considers my grandchild process as an orphan, and initaccepts it. This is similar to Linux 2.6 and NetBSD; I guess this is probably the norm, and POSIX doesn't seem to indicate that it is, so I was hoping for the opposite.

Since this approach will not work, I thought about using a call LD_PRELOADand intercepting my child process fork()and passing the information back to my parent process. However, I am concerned that it will not be as portable as the ideal solution, because different systems have different rules on how the dynamic linker does things like that LD_PRELOAD. It will not work for setuid / setgid graphical applications, either without an auxiliary library, which is also setuid or setgid, at least on Linux systems. This usually smells like a bad idea to me and looks pretty hacky.

, , - , , , LD_PRELOAD, , ( ).

+3
1

, , . - ( ), , .

AllTray . . , TERM KILL, , AllTray.

, , . , getpgid , , .

, , . , , , .

+1

Source: https://habr.com/ru/post/1710225/


All Articles