[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to recognize which child process has just ended?

Lukasz Muziol

8/7/2006 5:27:00 PM

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.

--
Posted via http://www.ruby-....

5 Answers

Francis Cianfrocca

8/7/2006 6:03:00 PM

0

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.

--
Posted via http://www.ruby-....

Ara.T.Howard

8/7/2006 6:48:00 PM

0

Francis Cianfrocca

8/7/2006 9:32:00 PM

0

unknown wrote:

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

That's a surprise, what made you think so? Is that true on Windows,
perhaps? On Unix no sig handler is needed. SIGCHLD is ignored by
default. The following works:

#----------------------

fork {exit 42}
fork {exit 2}

Process.wait2
Process.wait2

#----------------------

You can also call #wait and its variants with the flag Process::WNOHANG
if you want to poll. Use a SIGCHLD handler if you need to know instantly
when a child process finishes, but as always observe the standard
guidelines for coding signal handlers.

--
Posted via http://www.ruby-....

Ara.T.Howard

8/7/2006 9:49:00 PM

0

Lukasz Muziol

8/10/2006 7:51:00 PM

0

Thank you both.

As a matter of fact I do need to use a signal handler (the application
has an ncurses interface, so most of the time it's locked on getch calls
and action needs to be taken on child death), but the answer to my
problem is indeed the Process#wait2 method, which I somehow managed to
overlook.

--
Posted via http://www.ruby-....