Created
November 5, 2017 13:25
-
-
Save olastor/4f48edf411303e394b90a838c1a1dfef to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
if ((pid = fork()) < 0) { | |
// error occurred | |
printf("Error using fork()"); | |
return EXIT_FAILURE; | |
} else if(pid == 0) { | |
// child process | |
printf("In child process:\n"); | |
printf("\t- pid: %d\n", getpid()); | |
printf("\t- parent's pid: %d\n", getppid()); | |
} else { | |
// 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