Skip to content

Commit

Permalink
Finished the stack unwinding and winding functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
john-sharratt committed Sep 17, 2022
1 parent 6741d50 commit 91c3c79
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/fork.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>

int forkexample()
{
int x = 1;

int pid = fork();
if (pid == -1) {
printf("failed to fork - %d", errno);
return 1;
}

if (pid == 0)
printf("Child has x = %d\n", ++x);
else {
printf("Parent has x = %d\n", --x);

int status = 0;
waitpid(pid, &status, 0);
printf("Child(%d) exited with %d\n", pid, status);
}

return 0;
}
int main()
{
forkexample();
return 0;
}

0 comments on commit 91c3c79

Please sign in to comment.