forked from WebAssembly/wasi-libc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished the stack unwinding and winding functionality
- Loading branch information
1 parent
6741d50
commit 91c3c79
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |