2: static char help[] = "Tests signal handling.\n\n";
4: #include <petscsys.h>
5: #include <signal.h>
7: typedef struct _handlerCtx {
8: int exitHandler;
9: int signum;
10: } HandlerCtx;
12: int handleSignal(int signum, void *ctx)
13: {
14: HandlerCtx *user = (HandlerCtx*) ctx;
16: user->signum = signum;
17: if (signum == SIGHUP) user->exitHandler = 1;
18: return 0;
19: }
21: int main(int argc, char *args[])
22: {
23: HandlerCtx user;
25: user.exitHandler = 0;
27: PetscInitialize(&argc, &args, (char*) 0, help);
28: PetscPushSignalHandler(handleSignal, &user);
29: while (!user.exitHandler) {
30: if (user.signum > 0) {
31: PetscPrintf(PETSC_COMM_SELF, "Caught signal %d\n", user.signum);
32: user.signum = -1;
33: }
34: }
35: PetscPopSignalHandler();
36: PetscFinalize();
37: return 0;
38: }
40: /*TEST
42: build:
43: requires: !defined(PETSC_MISSING_SIGHUP)
45: test:
46: TODO: need to send a signal to the process to kill it from the test harness
48: TEST*/