Created
December 9, 2022 03:58
-
-
Save Blizzardo1/4202c525c931a06728f2addc4488630e 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 <sys/types.h> | |
#include <sys/wait.h> | |
#include <unistd.h> | |
int main(void) { | |
pid_t proc1 = fork(); | |
pid_t proc2 = fork(); | |
if(proc1 < 0 || proc2 < 0) { | |
perror("Forking failed"); | |
} | |
if(proc1 == 0) { | |
printf("I am the first child proccess: %d\n", (int) getpid()); | |
} | |
if(proc2 == 0) { | |
printf("I am the second child process: %d\n", (int) getpid()); | |
} | |
if(getpid() > 0) { | |
printf("I am the parent process: %d\n", (int) getpid()); | |
printf("Parent is waiting for children to die..."); | |
} | |
sleep(5); | |
wait(NULL); | |
printf("\nChildren are now dead!\n"); | |
exit(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment