Created
February 12, 2014 20:11
-
-
Save alecbz/8963583 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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