I have tested the "fork" and so called "copy-on-write" operation by
invoking the following command (as a normal user, not superuser).

perl -e '$| = 1; sub s1() { system("free -t | tail -1") } s1(); for ($i =
0; $i<10_000_000; $i++) { $a[$i] = 0 } s1(); if (\!fork()) { s1(); for ($i
= 0; $i<scalar(@a); $i+=300) { $a[$i] = 0 } s1() } else { wait() }'

First of all, suppose that my machine has 300M of free memory.
Then I allocate array of 10,000,000 integer elements, that will eat
memory about 200M.  Now, the amount of free memory is 100M.
Then I fork() 1 time, and let the child process to write on the allocated
array to force the "copy-on-write" operation.
But the free memory is not enough to "copy-on-write" the whole of
allocated array.  So, the system will run out of memory and crash.
And I can't find any method to recover my system without reseting the
hardware.

How can I protect this crash ?


ps. The testing time may be so long.  So, the "swapoff -a" command may be
    used to short the time.


Reply via email to