Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Busy box, Run C, python or Perl programs

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

like image 306
limovala Avatar asked May 06 '13 05:05

limovala


2 Answers

If your question is

Does busybox come with a python 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.

like image 86
Adrian Frühwirth Avatar answered Sep 29 '22 14:09

Adrian Frühwirth


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

like image 31
Tudor Constantin Avatar answered Sep 29 '22 14:09

Tudor Constantin