7

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

limovala
  • 459
  • 1
  • 5
  • 16
  • 1
    Possible duplicate: http://stackoverflow.com/questions/4964799/write-a-bash-shell-script-that-consumes-a-constant-amount-of-ram-for-a-user-defi – Andrey Sobolev May 06 '13 at 06:18
  • 1
    What system do you have? Have you installed Linux on your laptop/desktop (first, to learn Linux, and second, to cross-compile)? You could also consider using tinycc (i.e. `tcc` which compiles quickly C code into unoptimized machine code). – Basile Starynkevitch May 06 '13 at 06:35

2 Answers2

4

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.

Community
  • 1
  • 1
Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71
1

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

Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
  • Thanks, but I cannot run perl on the machine, I can use only busybox. And I found no way to run c or python or perl program using busybox – limovala May 06 '13 at 06:58
  • @AbhishekLal If you can't run Perl, why do you have it as a tag on the question? – Brad Gilbert May 07 '13 at 01:45
  • @Brad Gilbert I added it because of my doubt "Does busybox come with a python interpreter, perl or C compiler?" – limovala May 07 '13 at 05:05
  • @AbhishekLal [Busybox is a single executable that has a bunch of Unix utilities built-in.](http://www.busybox.net/about.html) The only programming language that it comes with is a shell language. – Brad Gilbert May 08 '13 at 00:27