<div dir="ltr">I've implemented some lightweight signal handling facilities. See the attached header and implementation files for a taste of the current API, and the pseudo-example code showing how to use it, briefly described below:<div><br></div><div>Right now I'm using it to interact with the job scheduler during (explicit) timestepping. I have being/end signal handling calls around TSSolve(). A PostStep() routine catches signals and handles them this way:</div><div><br><div><div>* If SIGINT or SIGTERM, I dump a restart file and set converged reason to  USER to stop.<br></div><div>* If SIGUSR1, I dump a restart file and continue timestepping.</div><div>* if SIGUSR2, I dump a VTK file and continue timestepping.<br><div><br></div><div>I can send signals to the job with `scancel -s SIG<NAME>`. When the job time allocation  is about to expire, SLURM fist sends SIGTERM and waits some time before SIGKILL. That time is enough to get a restart file from the last step, stop timestepping and finalize gracefully.</div><div></div><div><br></div><div>I'm not 100% happy with the API, maybe I should make it easier to use. For example, I could define each PETSC_SIGXXX so that I do need the macro PetscSigMask(). That would complicate a bit the mapping signal enum -> name string, though. I could also implement PetscSignalRaise(), it may be useful, but I'm not sure.</div><div><div><br></div><div>Do you think this may be of some value for core PETSc? I'm asking before submitting a MR because that would require writing some docs, I don't want to do the doc work before knowing your opinion first :-).</div><div><br></div><div>Regards,</div><div><br></div><div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Lisandro Dalcin<br>============<br>Research Scientist<br>Extreme Computing Research Center (ECRC)<br>King Abdullah University of Science and Technology (KAUST)<br><a href="http://ecrc.kaust.edu.sa/" target="_blank">http://ecrc.kaust.edu.sa/</a><br></div></div></div></div></div></div></div></div></div>