#include <stdlib.h> #include <unistd.h> #include <stdio.h> /* pstree output when trying rateau 10 -+= 51443 yunes ./rateau 10 |--- 51444 yunes ./rateau 10 |--- 51445 yunes ./rateau 10 |--- 51446 yunes ./rateau 10 |--- 51447 yunes ./rateau 10 |--- 51448 yunes ./rateau 10 |--- 51449 yunes ./rateau 10 |--- 51450 yunes ./rateau 10 |--- 51451 yunes ./rateau 10 |--- 51452 yunes ./rateau 10 \--- 51453 yunes ./rateau 10 */ // warning: no real error handling there... int main(int argc,char *argv[]) { int n; sscanf(argv[1],"%d",&n); for (int i=0; i<n; i++) { pid_t p = fork(); switch(p) { case -1: break; // error handling here... case 0: sleep(10); exit(0); // default: break; } } for (int i=0; i<n; i++) { if (wait(NULL)==-1) break; // } exit(0); }