On Tue, 8 Aug 2006, Francis Cianfrocca wrote:

> Lukasz Muziol wrote:
>> Hi!
>>
>> The piece of software I'm working on now needs to fork child processes
>> and execute different programs (which terminate themselves). Also, some
>> child processes need to be killed/stopped/resumed and action needs to be
>> taken when a child is terminated. When the parent receives & traps the
>> SIGCLD signal, how does it know which child it is regarding and whether
>> it has been ended, terminated, stopped or resumed?
>>
>> In brief, I need the information, which in C signal handling is
>> accessible via the siginfo_t structure.
>>
>> Thanks.
>
> Look at Process#wait2 and Process#waitpid2.

i don't think that's sufficient - one would still need a sig handler,
something along the lines of:


   harp:~ > cat a.rb
   require 'thread'

   q = Queue.new

   trap('SIGCHLD'){ q.push :go }

   reaper = Thread.new do
     Thread.abort_on_exception = true

     loop do
       q.pop
       pid, status = Process.wait2
       p [pid, status]
     end
   end


   fork{ exit 42 }
   sleep 1

   fork{ exit 2 }

   puts '...'
   sleep


   harp:~ > ruby a.rb
   [26939, #<Process::Status: pid=26939,exited(42)>]
   [26940, #<Process::Status: pid=26940,exited(2)>]
   ...


regards.

-a
-- 
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama