CPU, 메모리 부하 테스트 프로그램
eat_cpu_mem.c 코드 내용
#include #include #include #include #include // This program can be used for simple CPU and MEM load tests // This program puts almost 100% load on one cpu core and consumes specified amount of RAM (main memory) // Please note that the timing behaviour changes based on CPU clock etc., so tune the constant accordingly // Usage a.out int main( int argc, char *argv[] ) { long * holder, rand_val=989978777; int i; long long j, timed, long_type_mult_factor=134217728, mem_in_gb; double x=945346346464.3453453453,y=7899.345345345,z=2343523523.242342342; if( argc == 3 ) { // printf("The argument supplied is %s\n", argv[1]); timed = atoi(argv[1]) ; mem_in_gb = atoi(argv[2]) * long_type_mult_factor ; printf("This program will run for approximately %s minutes and consumes %s GB of RAM \n", argv[1], argv[2]); printf("Please note that this exists with SIGALRM (14) signal\n"); } else if( argc > 3 ) { printf("Usage a.out \n"); exit(0); } else { printf("Usage a.out \n"); exit(0); } // Allocate memory holder = calloc(mem_in_gb, sizeof(long)); memcpy(holder,&rand_val,sizeof(long)); alarm(timed*60); // Burst CPU while(1) { y = sqrt(x) * sin(z) * pow(25,y); } //free(holder); return 0; }
컴파일하여 바이너리 생성하기
# gcc -lm eat_cpu_mem.c -o eat_cpu_mem.o
테스트 실행하기
# ./eat_cpu_mem.o 2 1
2분 동안 약 1기가의 메모리를 소비함.
출처
Program to eat CPU and Memory on Linux - Electron Proton
Program to eat CPU and Memory on Linux