Skip to content

Instantly share code, notes, and snippets.

@alecbz
Created February 12, 2014 20:11
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 alecbz/8963583 to your computer and use it in GitHub Desktop.
Save alecbz/8963583 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdio.h>
int main() {
int i;
pid_t pid = fork();
if (pid == 0) {
printf("I am the child. I'm going to print 'Hello, World!' 15 times\n");
for (i = 0; i < 15; ++i) {
printf("Hello, World!\n");
}
} else {
printf("I am the parent. I'm going to print the first 10 powers of 2\n");
int a = 1;
for (i = 0; i < 10; ++i) {
printf("%d\n", a);
a *= 2;
}
}
printf("Both programs will print this when finished\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment