Skip to Content

A stick figure smiling

Here's a preview from my zine, Bite Size Linux!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
read the transcript!

On Linux, you start new processes using the fork() or clone() system call.

calling fork creates a child process that’s a copy of the caller

the cloned process has EXACTLY the same memory.

  • same heap
  • same stack
  • same memory maps

if the parent has 36B of memory, the child will too.

copying all that memory every time we fork would be slow and a waste of RAM

often processes call exec right after fork, which means they don’t use the parent process’s memory basically at all!

so Linux lets them share physical RAM and only copies the memory when one of them tries to write

process: I’d like to change that memory
Linux: okay! I’ll make you your own copy!

Linux does this by giving both the processes identical page tables.

(same RAM)
but it marks every page as read only.

when a process tries to write to a shared memory address:

  1. there’s a page fault=
  2. Linux makes a copy of the page & updates the page table
  3. the process continues, blissfully ignorant

process, happily: It’s just like I have my own copy

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)