in reply to Swap hog - I do not understand this behavoir
The funny thing is that above code does NOT use up any swap!
Your system will only use swap space if system wide memory utilization approaches or exceeds available physical memory. With per process virtual memory limited to 8192KB, each of your test processes can consume no more than this amount for the process itself and some additional amount for file buffers. You can see your total system memory and memory utilization with 'top' or 'vmstat'. Even if you have only 512MB on your system it will take more than 10 of your test processes to consume it all (10 processes would probably consume less than 100MB total).
As for your test processes running out of virtual memory: they are consuming about 100 bytes on each loop iteration (I don't know the exact amount but there is some overhead on the ~80 character string you are pushing onto your array in each iteration). It takes over 20,000 iterations to reach a total process memory utilization of 8192KB (22786 on my system) and, as others have pointed out, with a process being spawned and file I/O in each iteration, it takes considerable time to reach this number of iterations.
If you start your test and tail your output files, you should see them continue to grow until the processes fail. The child processes will continue after your main process has exited. Just be patient and eventually you should see an 'Out of memory!' for each child process.
|
|---|