Skip to content

Instantly share code, notes, and snippets.

@EteimZ
Created November 24, 2023 21:57
Show Gist options
  • Select an option

  • Save EteimZ/dec523a4741c8fcb45f9ca483b9567b5 to your computer and use it in GitHub Desktop.

Select an option

Save EteimZ/dec523a4741c8fcb45f9ca483b9567b5 to your computer and use it in GitHub Desktop.
Simple example of using fork in C.
#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