Separate memories
Process A and process B are two running programs. Each has its own memory, its address space, and the kernel keeps them apart: A cannot read or change B's memory. To work together they need inter-process communication, or IPC.
There are two basic ways. In message passing, the kernel carries a copy of the data across: a pipe works like this. In shared memory, both processes see the same page (a block of memory), and the kernel stays out of the way.
A pipe
Before splitting in two with fork, the program called pipe(fd). The kernel made a small buffer in its own memory, with two ends: fd[1] puts bytes in and fd[0] takes them out. After fork, both processes hold both ends.
Say B runs first and calls read(fd[0], buf, 3). That system call traps into the kernel, but the pipe is still empty, so the kernel does not return yet. It puts B to sleep: B is blocked, using no CPU, until data arrives.
A calls write(fd[1], "hi\n", 3). The system call traps into the kernel, which copies the 3 bytes h, i and newline from A's memory into the pipe buffer. That is copy one. write returns 3, and the kernel wakes B.
Now B's read can finish. The kernel copies the 3 bytes out of the pipe, oldest first, into buf in B's memory. That is copy two. read returns 3, and the pipe is empty again.
Shared memory
Also before fork, the program called mmap with MAP_SHARED. The kernel set aside one page, 4096 bytes, filled with zeros. After fork, that same physical page appears in A's address space and in B's.
A runs shared[0] = 42. This is a plain store instruction, not a system call. No trap, no kernel, no copy: the CPU writes 42 straight into the shared page at full speed.
Here is the catch: nothing in the page says when A is done. If B looked too early, it would see 0. So B first calls wait(NULL), which sleeps until A has finished. Only then is the store surely there.
B runs x = shared[0]. Another plain instruction: it reads 42 straight from the shared page into x. The kernel never touched or copied the number on its way from A to B.
A pipe costs two system calls and two copies per message, but the kernel handles the waiting and the order for you. Shared memory costs one mmap to set up, then runs at full speed, but you must synchronise yourself.
What happens
;; step 1/11 · walls
process A own memory (its address space)
process B own memory (its address space)
fork(2): "The child process and the parent process
run in separate memory spaces."
A writes its memory -> B sees nothing
IPC = inter-process communication: a channel
the kernel sets up between them
Which process runs first after fork is up to the scheduler. The figure shows B reaching read first, so it blocks; if A writes first, B finds the bytes waiting and read returns at once. The program prints the same either way. The cards show only the lines each process runs after fork. The whole program is real C99 with POSIX calls: it creates the pipe and the shared page, forks, and prints the bytes read and x.