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!
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:
- there’s a page fault=
- Linux makes a copy of the page & updates the page table
- 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!