egga has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks!
I have a problem and no idea how to solve it. I already spent some time googling and searching the monastery, but perhaps anyone can point me to the right node or site.
We have a script that builds up a large data structure and afterwards forks (we're on linux). The children do only read on that structure, so there is no need to copy it (which is important, because the machines don't have enough memory to handle a copy of the structure for each fork).
If we terminate the children using exit(), the structure is being copied for each child. If they get terminated using POSIX::_exit that will not happen. I think that is not nice and really would appreciate any other way to do that. Because I want an END block be called for each child and I don't have a clue, how to get this working.
If you wonder about that copy behavior, I prepared a small script, which proves the point (although i guess, most of you know it already). I watched my memory usage while execution and see a pretty high peak after the sleep if I alter the POSIX::_exit to a normal exit. Perhaps you need to adjust the array size for your computer...
#!/usr/bin/perl use strict; use warnings; use POSIX; my @array; for my $i (1 .. 100_000) { push @array, '-' x 1000; } print "before forking\n"; sleep 1; for (1 .. 10) { POSIX::_exit(0) unless fork; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Memory consumption of forks on exit
by salva (Canon) on May 19, 2011 at 11:10 UTC | |
by egga (Monk) on May 19, 2011 at 11:22 UTC | |
by Anonymous Monk on May 19, 2011 at 11:36 UTC | |
by egga (Monk) on May 19, 2011 at 11:45 UTC | |
by salva (Canon) on May 19, 2011 at 11:55 UTC | |
| |
Re: Memory consumption of forks on exit
by sundialsvc4 (Abbot) on May 19, 2011 at 14:09 UTC | |
by egga (Monk) on May 20, 2011 at 05:32 UTC |