Created
April 25, 2018 13:53
-
-
Save morsoinferno/8eede79de11662c84a36ac247984cf66 to your computer and use it in GitHub Desktop.
fork3.c
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 <sys/types.h> | |
#include <sys/wait.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char const *argv[]) | |
{ | |
int num; | |
pid_t pid; | |
for (num = 0; num < 3; num++) | |
{ | |
pid = fork(); | |
printf("Soy el proceso PID=%d y mi padre PID=%d\n", getpid(), getppid()); | |
if (pid != 0) | |
{ | |
break; | |
} | |
srandom(getpid()); | |
sleep(random()%3); | |
} | |
if (pid != 0) | |
{ | |
printf("fin del proceso PID=%d\n", wait(NULL)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment