繁忙盒子,运行C程序,Python或Perl程序

7
我所拥有的只是Bourne shell和BusyBox。 有没有办法运行Python脚本或编译C程序或其他语言,如Perl等? 例如: busybox python eatmemory.py 100M 或者 busybox gcc eatmemory.c 我需要创建一个进程,它将消耗特定数量的内存,并测试性能。 谢谢。

1
可能是重复问题:https://dev59.com/XG445IYBdhLWcg3wQX6G - Andrey Sobolev
1
你用什么操作系统?你在笔记本电脑/台式机上安装了Linux吗(首先是为了学习Linux,其次是为了交叉编译)?你也可以考虑使用tinycc(即tcc),它可以将C代码快速编译成非优化的机器码。 - Basile Starynkevitch
2个回答

4

如果您的问题是

busybox有带有python解释器或C编译器吗?

那么答案是否定的。

如果您的问题是

有没有一种方法可以编写一个脚本,在busyboxash shell下运行,仅为我分配一些内存?

那么请参阅这个答案,正如Andrey所建议的那样。


1
一个简单的 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代表兆字节


谢谢,但我无法在这台机器上运行perl,我只能使用busybox。 而且我找不到任何方法可以使用busybox运行c、python或perl程序。 - limovala
@AbhishekLal 如果你不能运行Perl,为什么要在问题标签中加入它? - Brad Gilbert
@Brad Gilbert 我添加它是因为我怀疑“busybox是否带有Python解释器、Perl或C编译器?” - limovala
@AbhishekLal【Busybox是一个单一的可执行文件,内置有许多Unix实用工具。】(http://www.busybox.net/about.html)它内置的唯一编程语言是shell语言。 - Brad Gilbert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接