#include #include #include /* This is initialised on startup by the Dynamite dynamic loader. */ int (*dynamite_ckpt_ptr)(int sig, void *info, void *context) = NULL; char ckptname[1024]; /* * By default, the Dynamite checkpoint signal handler terminates the * process. If you don't want the process to terminate, you must override * the USR1 signal and invoke the checkpoint handler directly. */ void usr1handler(int sig) { /* The meaning of the arguments: * * if sig == 0, it means that the checkpoint signal handler has not * been invoked by delivering a signal, but has been directly invoked * from the application, like any other function. In that case, the * meaning of the other 2 parameters changes: * * info: determines if the process terminates after checkpointing (0) * or not (any other value). * context: must contain the pathname to the checkpoint file. * The "$DPVM_CKPTDIR/ckptFileName" file is not generated in this case. * * Moreover, unlike usual signal handler, dynamite_ckpt_ptr returns an int, * which is only significant for the "info != 0" case. If it returns 0, * it indicates that the process was checkpointed, but not terminated. * If it returns 1, it means that this is a restart from the checkpoint. * * WARNING: this is all considered to be an internal interface, and is * subject to change without notice. */ if (dynamite_ckpt_ptr(0, (void*)1, ckptname)) fprintf(stderr,"Just restarted from checkpoint.\n"); signal(sig, usr1handler); } int main(void) { sprintf(ckptname, "%s/checkpointFile", getenv("DPVM_CKPTDIR")); signal(SIGUSR1, usr1handler); for (;;) { fprintf(stderr, "blah, blah\n"); sleep(5); } }