Because of COW, linux will assign a page to a child process only once it has been written to. It will also assign a new page for the stack only once it is changed. So for example, if after a fork()
syscall, we call printf in the child, since the stack has changed we will get a page fault.
However i'm not sure about the following code:
fork();
char *arr = mmap(... some args.. MAP_FILED|MAP_PRIVATE);
Since both father and son run the mmap, I would assume that a page fault will occure on the second line because we call a function (well a syscall, actually) and also create a local variable, hence changing the stack. Is this correct?
TL;DR:
Does mmap causes a page fault after we fork?