I am struggling to figure out how to correctly use systemu in a multithreaded environment. The use case is as follows.
I have a runner loop that will spawn any number on threads, where each of them could possibly make a call to systemu. The implementation on my side looks like this.
thread = Thread.current
@status = systemu(@command, opts) do |cid|
begin
while(thread.alive?)
sleep 0.1
end
Process.waitpid(cid) if Process.getpgid(cid)
rescue SystemExit
...
The goal here is to use the thread spawned by systemu to prevent defunct processes.
So the problem is, if the thread that made the call to systemu dies, there obviously is no way for the exit code to make it back to the main thread, leaving me with nil's.
Also, even with the guard thread attempting to clean up defunct processes, I still have users reporting them.
Am I missing something obvious? Any feedback will be greatly appreciated.
I am struggling to figure out how to correctly use systemu in a multithreaded environment. The use case is as follows.
I have a runner loop that will spawn any number on threads, where each of them could possibly make a call to systemu. The implementation on my side looks like this.
The goal here is to use the thread spawned by systemu to prevent defunct processes.
So the problem is, if the thread that made the call to systemu dies, there obviously is no way for the exit code to make it back to the main thread, leaving me with nil's.
Also, even with the guard thread attempting to clean up defunct processes, I still have users reporting them.
Am I missing something obvious? Any feedback will be greatly appreciated.