Boost C++ Libraries: Ticket #3921: Boost unit test & signals on linux https://svn.boost.org/trac10/ticket/3921 <p> Dears, </p> <p> The code below is working in the normal executable, but not in the test framework. The problem was very hard to find, because Linux tool are allowed to change order of the process execution. </p> <p> Generally the problem is caused by signal monitor from the test framework. After fork() something happens (execlp) and then child process when exiting emits SIGCHLD, this signal normally reaches parent process. In the boost unit test signal monitor catches it, but not re-emits, so parent process hangs. </p> <p> <em> for testing you may use ::std::string const process_name ("ls -al"); </em></p> <p> pid_t const pid = fork(); if (pid &lt; 0) { </p> <blockquote> <p> error = -1; </p> </blockquote> <p> } else { </p> <blockquote> <p> ::std::cerr &lt;&lt; <span class="underline">PRETTY_FUNCTION</span> &lt;&lt; ' ' &lt;&lt; <span class="underline">LINE</span> &lt;&lt; '\n'; if (pid == 0) <em> child { </em></p> <blockquote> <p> ::std::cerr &lt;&lt; <span class="underline">PRETTY_FUNCTION</span> &lt;&lt; ' ' &lt;&lt; <span class="underline">LINE</span> &lt;&lt; '\n'; ::boost::int32_t const ret (execlp (process_name.c_str(), process_name.c_str(), NULL)); </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> ::std::cerr &lt;&lt; <span class="underline">PRETTY_FUNCTION</span> &lt;&lt; ' ' &lt;&lt; <span class="underline">LINE</span> &lt;&lt; '\n'; <em> do not flush stdout _exit(127); </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> ::std::cerr &lt;&lt; <span class="underline">PRETTY_FUNCTION</span> &lt;&lt; ' ' &lt;&lt; <span class="underline">LINE</span> &lt;&lt; '\n'; </p> </blockquote> <p> } else { </p> <blockquote> <p> ::std::cerr &lt;&lt; <span class="underline">PRETTY_FUNCTION</span> &lt;&lt; ' ' &lt;&lt; <span class="underline">LINE</span> &lt;&lt; '\n'; <em> ignore waiting because we need to continue without waiting </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em>int const wt = waitpid(pid, NULL, WUNTRACED | WCONTINUED); int const wt = waitpid(pid, NULL, 0); </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> ::std::cerr &lt;&lt; "wt = " &lt;&lt; wt &lt;&lt; '\n'; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> if (wt &lt; 0) { </p> <blockquote> <p> ::std::cerr &lt;&lt; <span class="underline">PRETTY_FUNCTION</span> &lt;&lt; ' ' &lt;&lt; <span class="underline">LINE</span> &lt;&lt; '\n'; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3921 Trac 1.4.3 Steven Watanabe Fri, 11 Jun 2010 15:23:23 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3921#comment:1 https://svn.boost.org/trac10/ticket/3921#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Trunk Boost.Test doesn't catch SIGCHLD, as of <a class="changeset" href="https://svn.boost.org/trac10/changeset/57995" title="Avoid catching SIGCHILD altogether. One should exanine system call ...">[57995]</a>. See also <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3664" title="#3664: Bugs: SIGCHLD always considered fatal error (closed: fixed)">#3664</a>. </p> Ticket