Dear Wise Monks,

I am testing changes to my

limit.conf
on my RHEL4 system. I want to see what happens if I set my virtual memory very low ... like ...

$ ulimit -a ... virtual memory (kbytes, -v) 8192

... and then I run Perl script that fork's off some memory draining processes ... like so ...

$ cat swaphogger.pl #!/usr/bin/perl -w use strict; sub start_hogging_memory { my @blackhole; my $count = 0; print __FILE__ . " [" . __LINE__ . "] child [$$]\n"; open ( FH, "> ${0}_${$}.output" ) or die " could not open file +:$!\n"; my $swapon = `swapon -s | tail -1`; while ( 1 ) { chomp( $swapon ); print FH "[$swapon $count]\n"; push @blackhole, "$count ----------------------------- +------------------------------------------\n"; $count++; $swapon = `swapon -s | tail -1` # strangeness } close (FH); } my $maxChildren = shift; my $numChildren = 0; while ( $numChildren < $maxChildren ) { $numChildren++; my $pid = fork(); if ( $pid == 0 ) { start_hogging_memory (); } elsif ( $pid ) { print __FILE__ . " [" . __LINE__ . "] parent [$$]\n"; } else { die __FILE__ . " [" . __LINE__ . "] couldn't fork() :$ +!\n"; } }

The funny thing is that above code does NOT use up any swap! But if I comment out the line :

$swapon = `swapon -s | tail -1` # strangeness

... things work the way I would expect ....

$ ./swaphogger.pl 10 ./swaphogger.pl [8] child [2583] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2584] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2585] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2588] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2589] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2590] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2591] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2592] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2593] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2594] ./swaphogger.pl [30] parent [2582] rcecala@eman-sjc1-001: Priority=4 scripts$ Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory!

Why does the line ...

$swapon = `swapon -s | tail -1` # strangeness
... seem to fix my memory hole?


In reply to Swap hog - I do not understand this behavoir by Plankton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.