Ruby provides tools like Process.wait
and Signal.trap
to synchronize the forked processes. But how can you make sure that you will register only for first level child processes? E.g. if your main process starts process A and that one stars another subprocess B. If I use wait
/trap
in my main process, how can I specify interest in direct sub-processes like A and not sub-subprocesse like B?
For example:
Signal.trap("CLD") { counter += 1 }
Process.wait if counter <= 0
counter -= 1
fork { … }
I use this technique to limit the number of spawned child processes. But this breaks if child processes spawn more subprocesses.