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.
- Loading branch information
1 parent
8e96199
commit 1605470
Showing
8 changed files
with
514 additions
and
399 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
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,37 @@ | ||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
|
||
int main(void) { | ||
printf("Main program started\n"); | ||
|
||
int pid = vfork(); | ||
if (pid == -1) { | ||
printf("failed to fork - %d", errno); | ||
return 1; | ||
} | ||
|
||
if (pid == 0) { | ||
printf("execve: echo hi-from-child\n"); | ||
char* argv[] = { "echo", "hi-from-child", NULL }; | ||
char* envp[] = { NULL }; | ||
if (execve("echo", argv, envp) == -1) { | ||
perror("Could not execve"); | ||
} | ||
} else { | ||
int status = 0; | ||
waitpid(pid, &status, 0); | ||
printf("Child(%d) exited with %d\n", pid, status); | ||
|
||
printf("execve: echo hi-from-parent\n"); | ||
char* argv[] = { "echo", "hi-from-parent", NULL }; | ||
char* envp[] = { NULL }; | ||
if (execve("echo", argv, envp) == -1) { | ||
perror("Could not execve"); | ||
} | ||
} | ||
|
||
return 1; | ||
} |
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,31 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <unistd.h> | ||
#include <spawn.h> | ||
#include <sys/wait.h> | ||
|
||
extern char **environ; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
pid_t pid; | ||
char *child_argv[] = {"echo", "hi", NULL}; | ||
int status; | ||
status = posix_spawn(&pid, "echo", NULL, NULL, child_argv, environ); | ||
if (status == 0) { | ||
printf("Child pid: %i\n", pid); | ||
do { | ||
if (waitpid(pid, &status, 0) != -1) { | ||
printf("Child status %d\n", WEXITSTATUS(status)); | ||
} else { | ||
perror("waitpid"); | ||
exit(1); | ||
} | ||
} while (!WIFEXITED(status) && !WIFSIGNALED(status)); | ||
} else { | ||
printf("posix_spawn: %s\n", strerror(status)); | ||
} | ||
return 0; | ||
} |
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,24 @@ | ||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
|
||
int main() { | ||
int pid = vfork(); | ||
if (pid == -1) { | ||
printf("failed to fork - %d", errno); | ||
return 1; | ||
} | ||
|
||
if (pid == 0) | ||
_exit(10); | ||
else { | ||
printf("Parent waiting on Child(%d)\n", pid); | ||
|
||
int status = 0; | ||
waitpid(pid, &status, 0); | ||
printf("Child(%d) exited with %d\n", pid, status); | ||
} | ||
return 0; | ||
} |
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
Oops, something went wrong.