【问题标题】:Busy box, Run C, python or Perl programs忙箱、运行 C、python 或 Perl 程序
【发布时间】:2013-04-29 20:06:40
【问题描述】:

我只有 bourne shell 和忙碌的盒子。 有什么方法可以运行 python 脚本或编译 c 程序或任何语言,如 perl ..

喜欢 busybox python eatmemory.py 100M

busybox gcc eatmemory.c

我需要的是创建一个消耗特定内存量的进程。并测试性能。

谢谢

【问题讨论】:

  • 你有什么系统?您是否在笔记本电脑/台式机上安装了 Linux(首先是学习 Linux,其次是交叉编译)?您还可以考虑使用 tinycc(即tcc,它可以将 C 代码快速编译成未优化的机器代码)。

标签: python linux perl gcc busybox


【解决方案1】:

如果你的问题是

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

那么答案是否定的。

如果是的话

有没有办法编写一个在busybox'ash shell 下运行的脚本,它只会为我分配一些内存?

然后按照 Andrey 的建议查看 this 答案。

【讨论】:

    【解决方案2】:

    一个简单的 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程序
    • @AbhishekLal 如果你不能运行 Perl,为什么要把它作为问题的标签?
    • @Brad Gilbert 我添加它是因为我怀疑“busybox 是否带有 python 解释器、perl 或 C 编译器?”
    • @AbhishekLal Busybox is a single executable that has a bunch of Unix utilities built-in. 它附带的唯一编程语言是 shell 语言。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多