$ ulimit -a
...
virtual memory (kbytes, -v) 8192
####
$ 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";
}
}
####
$swapon = `swapon -s | tail -1` # strangeness
####
$ ./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!
####
$swapon = `swapon -s | tail -1` # strangeness