我所拥有的只是 bourne shell 和忙碌的盒子。有什么方法可以运行 python 脚本或编译 ac 程序或任何语言,如 perl ..
像
busybox python eatmemory.py 100M
或者
busybox gcc eatmemory.c
我需要的是创建一个消耗特定内存量的进程。并测试性能。
谢谢
如果你的问题是
是否
busybox
带有python
解释器或 C 编译器?
那么答案是否定的。
如果是
有没有办法编写一个在
busybox
'ash
shell 下运行的脚本,它只会为我分配一些内存?
然后按照安德烈的建议查看这个答案。
一个简单的 perl 脚本:
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";
假设您命名脚本eat_memory.pl
,请通过以下方式启动它:
perl eat_memory.pl 150
其中 150 代表兆字节