Skip to content

Instantly share code, notes, and snippets.

@mikeboers
Created May 15, 2013 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeboers/5586013 to your computer and use it in GitHub Desktop.
Save mikeboers/5586013 to your computer and use it in GitHub Desktop.
Tiny fork example
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.
#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