<div class="gmail_quote">On Wed, Jun 22, 2011 at 03:07, John Fettig <span dir="ltr">&lt;<a href="mailto:john.fettig@gmail.com">john.fettig@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":2tu">I am trying to start my program in gdb, using the options<br>
<br>
-start_in_debugger -debug_terminal &quot;screen -X -S debug screen&quot;<br>
<br>
where I have a running screen named debug.  If I run with e.g. -np 4,<br>
all 4 processes report that they are being attached by gdb, but in the<br>
screen session only 2 new windows show up.  If I run with -np 2, only<br>
1 new window shows up.</div></blockquote><div><br></div><div>I&#39;ve seen this, but only inconsistently (race condition) and only with Open MPI (not with MPICH2).</div><div><br></div><div>Are you using MPICH2 or Open MPI? I think MPICH2 might be setting SA_NOCLDSTOP which is saving us from the following race condition:</div>
<div><br></div><div>1. process is forked</div><div>2a. parent sleeps</div><div>2b. child gets parent PID and execs the screen attach command</div><div>3. screen attach command returns immediately, before actually running the command (invoking gdb)</div>
<div>4. child exits, generates SIGCHLD which wakes up parent</div><div>5. parent continues onward, possibly completing and exiting</div><div>6. screen session gets around to invoking gdb and attaching to the parent process, but it has already exited</div>
<div>(sometimes some of the processes have exited while others are still in MPI_Finalize or similar)</div><div><br></div><div>I think the solution is to use sigaction(3) to set SA_NOCLDSTOP so that the child terminating does not generate SIGCHLD. The man page points out that this is typically the desired behavior.</div>
<div><br></div><div>Is there some obscure platform that supports signal(), but not sigaction() or can we use sigaction() for everything?</div><div><br></div></div>