DEV Community

Cover image for How the fork() System Call Actually Works in Linux
Binary Dose
Binary Dose

Posted on Originally published at binarydose.in

How the fork() System Call Actually Works in Linux

The fork() System Call

pid_t pid = fork();
if (pid == 0) {
    printf("I am the child!\n");
} else {
    printf("I am the parent of %d!\n", pid);
}
Enter fullscreen mode Exit fullscreen mode

⚡ Copy-on-Write (COW)

Rather than copying gigabytes of RAM during fork(), the kernel marks all page table entries as read-only. A page is physically cloned only when one process attempts to write to it.

Explore the full interactive process lifecycle on Binary Dose.

Top comments (0)