Signals from child process can't interrupt wait() from parent?

Signals from child process can't interrupt wait() from parent?

Post by Mario Nigrovi » Tue, 11 Jul 2000 04:00:00



Hi -

   I have a really weird thing happening, and it LOOKS like what happens
is that when the parent (who is wait()ing on it's child) catches a
signal issued by that child process, the wait() is NOT interrupted.  This
is happening on Solaris 2.6.  Is this correct behavior?

   Here's the background:

   I've got a nifty RPC server routine which the client can kick-start if
it's not already there.  The idea is that the client will just wait for the
server to initialize, and then contact it.  So the client fork()s and
then execl()s the server process.  The server process fork()s off
the child to do the real work, then is supposed to hang around until the
child is initialized (ie, gets past the svc_create() successfully).  This
way, when the client's wait() completes with a 0 status, it knows the
server is ready for it.

   The simple solution seemed to be to have the parent schedule an alarm()
for itself just before the fork() and then wait() just after the fork().
If the child exits for other reasons, the wait() returns the pid; if the
wait() gets interrupted by SIGHUP, or SIGALRM (the latter if the server
never responded or exited), then wait() should return -1 and set errno to
EINTR.

   Yet, in practice, the server receives the SIGHUP (and prints a debug
message to that effect), then goes on wait()ing until the SIGALRM, at which
point the wait() returns -1 and sets errno to EINTR.

   While it's wait()ing, I *can* send a SIGHUP (-1) to the server process
from another shell and the wait() will be interrupted, but, somehow,
this doesn't work if the SIGHUP is coming from the child!

   Is this the correct behavior?  Is there something the signal handler
should do to break the wait()?  The signal handler DOES report receipt of
the SIGHUP, so I know the signal is being delivered correctly.

   As I'm writing this, it occurs to me that I can just put a signal handler
in for SIGCHLD, stuff the wait() into it and use pause() to wait for any
of the three expected signals.  But my curiosity remains, how/why is wait()
ignoring signals from the child, or what is really going on?

   My platform is a Sun UltraSPARC 30 running Solaris 2.6.

                                Thanks for your time,

                                        Mario

 
 
 

Signals from child process can't interrupt wait() from parent?

Post by Mario Nigrovi » Wed, 12 Jul 2000 04:00:00



> Hi -

>    I have a really weird thing happening, and it LOOKS like what happens
> is that when the parent (who is wait()ing on it's child) catches a
> signal issued by that child process, the wait() is NOT interrupted.  This
> is happening on Solaris 2.6.  Is this correct behavior?

DOH!

    The child is signaling the parent before the parent gets the chance
to wait(), so OF COURSE the wait() doesn't get interrupted.

                                        Mario
--
 <|  A crash reduces          |>
  |> Your expensive computer <|


 
 
 

1. Child Process Waiting for Parent Process

Hello Everybody:

If I want to make a UNIX child process wait until its parent exits
before the child
process proceeds with what it needs to do, is there any other way than
using
condition variables in shared memory which is the general way of
synchronizing
unrelated processes? By other way I mean something similar to the
waitpid()
API but applies in the reverse direction? After all, this case qualifies
as trying
to synchronize two related processes.

Thanks in advance for any information!

Bob

2. open office on linux alpha?

3. waitpid in parent process doesn't wait when parent receives a sigterm.

4. help needed to fix a can-not-boot problem

5. Can a child process change the parent process's directory?

6. masquerading in 2.1.x kernels?

7. How to wait for two(or more) children in parent process?

8. Bush is a killer! STOP HIM!!!!!!!!!!!!!!

9. signals: stop child, parent told child died !

10. interrupts, wait(), child process

11. Signals/Parent/child process

12. Solaris SMP machines and SIGALRM in child process 'propagated' to parent

13. Child of xterm window doesn't see signal when parent receives SIGINT