Created
May 15, 2013 18:08
-
-
Save mikeboers/5586013 to your computer and use it in GitHub Desktop.
Tiny fork example
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
2013-05-15 11:06:20 mikeboers@faraday: ~/Desktop | |
$ gcc fork.c | |
2013-05-15 11:07:25 mikeboers@faraday: ~/Desktop | |
$ ./a.out | |
Before the fork. | |
I am the parent of 9761. | |
I am the child. |
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
#include <unistd.h> | |
#include <stdio.h> | |
int main(int argc, char **argv) { | |
printf("Before the fork.\n"); | |
int pid = fork(); | |
if (pid) { | |
printf("I am the parent of %d.\n", pid); | |
} else { | |
printf("I am the child.\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment