<div dir="ltr">PETSc's signal handler is for segvs, etc. I don't know the details but I don't think we care about external signals.<div><br></div><div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 7, 2017 at 7:17 AM, Gard Spreemann <span dir="ltr"><<a href="mailto:gspr@nonempty.org" target="_blank">gspr@nonempty.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello list,<br>
<br>
I seem to be misunderstanding how to install a signal handler with<br>
PETSc. If I send the USR1 signal to a program with the below code, it<br>
exits with a non-zero exit code as if no signal handler were<br>
intalled. I'd appreciate if someone could shed some light on the<br>
matter.<br>
<br>
***<br>
<br>
#include <stdio.h><br>
#include <signal.h><br>
#include <unistd.h><br>
#include <string.h><br>
#include <petscmat.h><br>
#include <petscsys.h><br>
<br>
PetscErrorCode handler(int signum, void * ctx)<br>
{<br>
if (signum == SIGUSR1)<br>
{<br>
*((sig_atomic_t *) ctx) = 1;<br>
}<br>
return 0;<br>
}<br>
<br>
<br>
int main(int argc, char ** argv)<br>
{<br>
printf("I am %lu, hear me roar.\n", getpid());<br>
<br>
PetscInitialize(&argc, &argv, NULL, NULL);<br>
<br>
sig_atomic_t flag = 0;<br>
PetscErrorCode err;<br>
err = PetscPopSignalHandler(); CHKERRQ(err);<br>
err = PetscPushSignalHandler(<wbr>handler, (void *)&flag); CHKERRQ(err);<br>
<br>
for (int i = 0; i < 20; i++)<br>
{<br>
printf("I'm awake. Did anything happen?\n");<br>
if (flag)<br>
{<br>
printf("YES!\n");<br>
return 0;<br>
}<br>
else<br>
printf("No...\n");<br>
<br>
err = PetscSleep(5); CHKERRQ(err);<br>
}<br>
<br>
PetscFinalize();<br>
return 0;<br>
}<br>
<br>
<br>
***<br>
<br>
<br>
Best regards,<br>
Gard Spreemann<br>
<br>
</blockquote></div><br></div>