Skip to content

Instantly share code, notes, and snippets.

@cs-fedy
Created August 29, 2020 10:21
Show Gist options
  • Save cs-fedy/8ce5bd6cba5a233442038697b5afd9d4 to your computer and use it in GitHub Desktop.
Save cs-fedy/8ce5bd6cba5a233442038697b5afd9d4 to your computer and use it in GitHub Desktop.
process creation using posix in c.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
int main() {
int x, y;
x = fork();
if (x == 0) {
printf("I'm the child %d of %d\n", getpid(), getppid());
exit(3);
} else if (x == -1) {
printf("error!!\n");
} else {
y=wait(NULL);
printf("hello world it is me the father of %d and the child of %d\n", y, getppid());
printf("==== the end ====\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment