Created
November 5, 2017 13:44
-
-
Save olastor/c3213fd171c2a32b5b9286740e37c9ed 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 <unistd.h> | |
int main() { | |
pid_t pid; | |
switch ((pid = fork())) { | |
case -1: | |
// error occurred | |
printf("Error using fork()"); | |
break; | |
case 0: | |
// child process | |
printf("In child process:\n"); | |
printf("\t- pid: %d\n", getpid()); | |
printf("\t- parent's pid: %d\n", getppid()); | |
break; | |
default: | |
// parent process | |
printf("In parent process:\n"); | |
printf("\t- pid: %d\n", getpid()); | |
printf("\t- child's pid: %d\n", pid); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment