2013-05-06 1 views
5

내가 가지고있는 것은 모두 본쉘과 바쁜 상자입니다. 파이썬 스크립트를 실행하거나 교류 프로그램이나 펄 등은 언어를 컴파일 할 수있는 방법이 있나요 .. busybox python eatmemory.py 100M바쁜 상자, 실행 C, 파이썬 또는 Perl 프로그램

또는

같은

busybox gcc eatmemory.c

나는 프로세스를 생성하는 것입니다 필요한 것은 특정 양의 메모리를 소비합니다. 성능을 테스트하십시오.

감사

+1

가능한 복제본 : http://stackoverflow.com/questions/4964799/write-a-bash-shell-script-that-consumes-a-constant-amount-of-ram-for-a-user-defi –

+1

어떤 시스템이 있습니까? 랩탑/데스크탑에 Linux를 설치 했습니까? (처음에는 Linux를 배우고, 두 번째는 크로스 컴파일해야합니다.) tinycc (즉, C 코드를 최적화되지 않은 머신 코드로 빠르게 컴파일하는 'tcc')를 사용할 수도 있습니다. –

답변

3

하는 경우를 나타냅니다

perl eat_memory.pl 150 

당신의 질문은

입니다.

busyboxpython 인터프리터 또는 C 컴파일러와 함께 제공됩니까?

그러면 대답은 아니오입니다.

그냥 날 위해 약간의 메모리를 할당합니다 ash 쉘 'busybox에서 실행하는 스크립트를 작성하는 방법이 경우?

다음은 Andrey의 제안에 따라 this 답을 참조하십시오.

1

간단한 펄 스크립트 : 스크립트 eat_memory.pl 이름을 가정

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"; 

가,하여 시작 : 150 메가 바이트

+0

고마워,하지만 컴퓨터에서 perl을 실행할 수 없다. 나는 busybox 만 사용할 수있다. 그리고 busybox를 사용하여 c 또는 python이나 perl 프로그램을 실행할 수있는 방법이 없습니다. – limovala

+0

@AbhishekLal Perl을 실행할 수없는 경우 왜 질문에 태그를 사용합니까? –

+0

@Brad Gilbert 필자는 의심의 여지가 있기 때문에 "busybox에 파이썬 인터프리터, perl 또는 C 컴파일러가 있습니까?" – limovala