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