Created
February 23, 2016 23:39
-
-
Save RicardoLara/c6fc86914a1ada321bd3 to your computer and use it in GitHub Desktop.
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<unistd.h> | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<sys/types> | |
#include<sys/wait> | |
int main(){ | |
pid_t proceso; | |
for(i=0; i<4; i++){ | |
proceso = fork(); | |
switch(proceso){ | |
case -1: printf("ERROR\n"); break; | |
case 0: | |
if(!getpid()%2) | |
proceso = fork(); printf("Mi pit: %d, Hijo de %d\n",getpid(),getppid()); break; | |
case 1: proceso = fork(); printf("Mi pit: %d, Hijo de %d\n",getpid(),getppid()); break; | |
default: printf("Mi pit: %d\n",getpid()); for(j=0; j<2; j++) proceso = fork(); wait(&status); break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment