Last active
February 5, 2018 11:53
-
-
Save nampereira/56b6e97ff02a8b0e1624725912630601 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 <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <wait.h> | |
void main() | |
{ | |
int i; | |
int status; | |
for (i = 0; i < 2; i++) | |
if (fork() == 0) { /* Child */ | |
sleep(i+1); | |
exit(i+1); | |
} | |
for (i = 0; i < 2; i++) { /* Parent */ | |
pid_t wpid = wait(&status); | |
if (WIFEXITED(status)) | |
printf("Child with PID %d terminated with exit status %d\n", wpid, WEXITSTATUS(status)); | |
else | |
printf("Child with PID %d terminated abnormally\n", wpid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment