Nine Bytes Of Fork

size_t n = 512UL * 1024 * 1024;          /* 512 Mi ints = 2 GiB */
int *heap = malloc(n * sizeof(int));
memset(heap, 0, n * sizeof(int));        /* every page resident */
heap[0] = 7;

if (fork() == 0) {
    heap[0] = 9;
    _exit(0);
}
wait(NULL);
printf("%d\n", heap[0]);

The machine has 8 GiB of RAM and no swap. What does the parent print, and roughly how much additional physical memory does the fork cause the kernel to allocate for the heap?

A

prints 9; about 4 KiB

B

prints 7; about 4 KiB

C

prints 9; nothing, parent and child share the heap

D

prints 7; about 2 GiB