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?
Sign in to answer questions and track your progress
Sign In