1: /*$Id: ex1.c,v 1.18 2003/08/08 21:30:50 knepley Exp $*/ 3: static char help[] = "Tests signal handling.\n\n"; 5: #include <petscsys.h> 6: #include <signal.h> 8: typedef struct _handlerCtx { 9: int exitHandler; 10: int signum; 11: } HandlerCtx; 15: int handleSignal(int signum, void *ctx) 16: { 17: HandlerCtx *user = (HandlerCtx *) ctx; 19: user->signum = signum; 20: if (signum == SIGHUP) { 21: user->exitHandler = 1; 22: } 23: return 0; 24: } 28: int main(int argc, char *args[]) 29: { 30: HandlerCtx user; 33: user.exitHandler = 0; 35: PetscInitialize(&argc, &args, (char *) 0, help); 36: PetscPushSignalHandler(handleSignal, &user); 37: while(!user.exitHandler) { 38: if (user.signum > 0) { 39: PetscPrintf(PETSC_COMM_SELF, "Caught signal %d\n", user.signum); 40: user.signum = -1; 41: } 42: } 43: PetscPopSignalHandler(); 44: PetscFinalize(); 45: return 0; 46: }