The parent process fails with errno=12(Out of memory) when it tries to fork a child. The parent process runs on Linux 3.0 kernel - SLES 11. At the point of forking the child, the parent process has already used up around 70% of the RAM(180GB/256GB). Is there any workaround for this problem?
The application is written in C++, compiled with g++ 4.6.3.
fork-ing requires resources, since it is copy-on-writing the writable pages of the process. Read again the fork(2) man page.You could at least provide a huge temporary swap file. You could create (on some file system with enough space) a huge file
$SWAPFILEwithOtherwise, you could for instance design your program differently, e.g.
mmap-ing some big file (andmunmap-ing it just before the fork, andmmap-ing it again after), or more simply starting at the beginning of your program apopen-ed shell, or ap2open-ed one or making explicitly thepipe-s to and from it (probably a multiplexing call à lapollwould also be useful), and later issue commands to it.Maybe we could help more if we had an idea of what your program is doing, why does it consume so much memory, and why and what is it forking...
Read Advanced Linux Programming for more.
PS.
If you
forkjust to rungdbto show the backtrace, consider simpler alternatives like recent GCC's libbacktrace or Wolf's libbacktrace...