All I have is bourne shell and busy box. Is there any way to run a python script or compile a c program or any languages like perl ..
like
busybox python eatmemory.py 100M
or
busybox gcc eatmemory.c
What I need is to create a process which will consume a specific amount of memory. and test the performance.
Thanks
If your question is
Does
busybox
come with apython
interpreter or C compiler?
then the answer is no.
If it is
Is there a way to write a script that will run under
busybox
'ash
shell which will just allocate some memory for me?
then see this answer, as suggested by Andrey.
a simple perl script:
use strict;
use warnings;
# store and validate the command line parameter
my $mb = $ARGV[0];
unless ( defined $mb and $mb =~ /^\d+$/ and $mb >= 1) {
die "Usage: $0 <occupy MB>\nEx: $0 100 - occupies 100 MB memory\n"
}
# convert it to bytes.
my $b = $mb * 1024 * 1024;
my $memfile;
# open in-memory file, and seek to size specified to get memory from OS.
open MEM, '>', \$memfile;
seek MEM, $b - 1, 0;
print MEM 'A';
close MEM;
printf "$mb MB memory is occupied, press ENTER to release: "; <STDIN>;
# till here the memory is occupied by this program.
undef $memfile;
printf "Memory released";
assuming you name the script eat_memory.pl
, start it by:
perl eat_memory.pl 150
where the 150 represents megabytes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With