Created
October 25, 2012 18:40
-
-
Save jdpaton/3954580 to your computer and use it in GitHub Desktop.
Fork x number of child processes which have a set lifetime
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 <stdio.h> | |
#include <stdlib.h> | |
static int expiry = 30; | |
int main(int argc, char *argv[]){ | |
int k = *argv[1]; | |
int i=0; | |
for(i = 0; i<k; i++){ | |
if(fork() == 0){ | |
printf("Forked child %d %d\n", i, ++k); | |
sleep(expiry); | |
printf("Forked child %d done\n",i); | |
exit(0); | |
}else{ | |
fprintf(stderr, "!! Unable to fork child: %d", i); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment