I'm trying the CoW of fork (see edit for more detailed background, which may be quite unrelated)
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#define N 262144
struct {
int n;
int padding[1023];
} arr[N];
int main() {
int i, sp = 0, t, tx = clock();
for (i=0; i<N; ++i) arr[i].n = i;
printf ("Init Time: %d\n", clock()-tx);
#if 1
sp = fork();
if(!sp) _exit(0);
waitpid(sp, &sp, 0);
#endif
// 5045 without fork
// 104192 with fork
t = clock();
for (i=0; i<N; ++i) arr[i].n = -i;
printf ("Runner %d Time: %d\n", sp, clock() - t);
getchar();
return 0;
}
The fork makes later memory accesses slower.
Do fork copy making it slow? If so, why? I run on Ubuntu 20.04.3 LTS