Skip to content

Instantly share code, notes, and snippets.

@RicardoLara
Created February 23, 2016 23:39
Show Gist options
  • Save RicardoLara/c6fc86914a1ada321bd3 to your computer and use it in GitHub Desktop.
Save RicardoLara/c6fc86914a1ada321bd3 to your computer and use it in GitHub Desktop.
#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