New system call: fork
- Here is the simplest of programs that knows how to create other processes. It uses a system call named fork.
- Code is in lecture examples folder: processes/basic-fork.c. Code is also right here.
static const int kForkFailed = 1;
int main(int argc, char *argv[]) {
printf("Greetings from process %d! (parent %d)\n", getpid(), getppid());
pid_t pid = fork();
exitIf(pid == -1, kForkFailed, stderr, "fork function failed.\n");
printf("Bye-bye from process %d! (parent %d)\n", getpid(), getppid());
return 0;
}