Skip to content

Instantly share code, notes, and snippets.

@hamadu
Last active August 7, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamadu/5dd7f9e29605cfe32a293f2ba568ab1c to your computer and use it in GitHub Desktop.
Save hamadu/5dd7f9e29605cfe32a293f2ba568ab1c to your computer and use it in GitHub Desktop.
wait
#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