Skip to content

Commit

Permalink
longjmp
Browse files Browse the repository at this point in the history
  • Loading branch information
kumail074 committed Nov 22, 2024
1 parent ef54ed4 commit 2928bd9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions learning/processes/longjmp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <tlpi.h>
#include <setjmp.h>

static jmp_buf env;

static void f2(void) {
longjmp(env, 2);
}

static void f1(int argc) {
if(argc == 1)
longjmp(env, 1);
f2();
}

int main(int argc, char *argv[]) {
switch (setjmp(env)) {
case 0:
printf("calling f1() after initial setjmp()\n");
f1(argc);
break;

case 1:
printf("came back from f1()\n");
break;

case 2:
printf("came back from f2()\n");
break;
}
exit(EXIT_SUCCESS);
}

0 comments on commit 2928bd9

Please sign in to comment.