[petsc-users] Help with PETSc signal handling
Mark Adams
mfadams at lbl.gov
Tue Nov 7 06:35:36 CST 2017
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 <gspr at nonempty.org> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20171107/a11442d4/attachment.html>
More information about the petsc-users
mailing list