Created
November 24, 2023 21:57
-
-
Save EteimZ/dec523a4741c8fcb45f9ca483b9567b5 to your computer and use it in GitHub Desktop.
Simple example of using fork in C.
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 <unistd.h> | |
| int main() { | |
| pid_t pid = fork(); | |
| if (pid == -1) { | |
| perror("Fork failed"); | |
| return 1; | |
| } | |
| if (pid == 0) { | |
| // Child process | |
| printf("Child process\n"); | |
| } else { | |
| // Parent process | |
| printf("Parent process\n"); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment