Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <setjmp.h> // setjmp/longjmp
- #include <unistd.h> // sleep
- #include <stdio.h> // printf
- #include <stdlib.h> // exit, atexit
- jmp_buf panic_restart;
- int panic_restart_count=0;
- void
- do_the_panic_restart()
- {
- if (panic_restart_count++ < 3)
- longjmp(panic_restart, 1);
- }
- int
- main(int argc, char **argv)
- {
- if(setjmp(panic_restart)) {
- fprintf(stderr,"PANIC! main() has been restarted due to a unscheduled exit!\n");
- }
- atexit(&do_the_panic_restart);
- printf("This is main. I will sleep a while, then try to exit.\n");
- sleep(1);
- exit(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement