Last active
August 7, 2017 14:50
-
-
Save hamadu/5dd7f9e29605cfe32a293f2ba568ab1c to your computer and use it in GitHub Desktop.
wait
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 <errno.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
void print_error_and_exit() { | |
printf("error(%d): %s\n", errno, strerror(errno)); | |
exit(1); | |
} | |
int main(int argc, char* argv[]) { | |
int status; | |
pid_t result = fork(); | |
if (result == -1) { | |
print_error_and_exit(); | |
} | |
if (result == 0) { | |
printf("hi. this is child process\n"); | |
sleep(3); | |
} else { | |
waitpid(result, &status, 0); | |
printf("hi. this is parent process\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment