1 #include <stdlib.h> 2 #include <sys/wait.h> 3 #include <unistd.h> 4 5 constexpr int LOOP_COUNT = 100000000; 6 7 volatile int a[2]; ParentFunction()8void ParentFunction() { 9 volatile int* p = a + atoi("0"); 10 for (int i = 0; i < LOOP_COUNT; ++i) { 11 *p = i; 12 } 13 } 14 ChildFunction()15void ChildFunction() { 16 volatile int* p = a + atoi("1"); 17 for (int i = 0; i < LOOP_COUNT; ++i) { 18 *p = i; 19 } 20 } 21 main()22int main() { 23 while (true) { 24 pid_t pid = fork(); 25 if (pid == 0) { 26 ChildFunction(); 27 return 0; 28 } else { 29 ParentFunction(); 30 waitpid(pid, nullptr, 0); 31 } 32 } 33 return 0; 34 } 35