Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need it execute a certain kind of linux program from the terminal. The only thing the linux program needs to do is use more and more memory. Are there any programs like that?

share|improve this question
    
trying to do something like this? –  KronoS May 4 '11 at 5:18
3  
Most poorly written programs will use more and more memory :) –  ta.speot.is May 4 '11 at 5:47
add comment

6 Answers 6

up vote 7 down vote accepted

From my previous answer on StackOverflow:

#include <stdlib.h>

int main() {
int *p;
while(1) {
    int inc=1024*1024*sizeof(char);
    p=(int*) calloc(1,inc);
    if(!p) break;
    }
}

run

$ gcc memtest.c
$ ./a.out

upon running, this code fills up ones RAM until killed by the kernel. Using calloc instead of malloc to prevent "lazy evaluation". Ideas taken from this thread: http://stackoverflow.com/questions/4383059/malloc-memory-questions

This code quickly filled my RAM (4Gb) and then in about 2 minutes my 20Gb swap partition before it died. This works on 64bit Linux. If you use a 32bit OS, it will have a limit of 2 or 4GB before it dies.

share|improve this answer
add comment

how about a fork bomb ?

else something that creates a series of ever larger ram disks? You can create a ram disk with

mkdir /tmp/ramdisk; chmod 777 /tmp/ramdisk

mount -t tmpfs -o size=256M tmpfs /tmp/ramdisk/

to create a 256 mb ram disk. you could probably script a script that will make a series of ram disks, and fill them repeatedly up until whatever you need would happen

share|improve this answer
2  
+1 for fork bomb - probably the most simple solution here. OP never mentioned monitoring the used memory. –  new123456 May 4 '11 at 11:06
add comment

Save the following as mem.c, then run gcc -o mem mem.c, then run ./mem. It allocates 100MB of memory every second. It does nothing else. You can change the number of seconds its sleeps or how many MB it allocates by changing the numbers below.

#include <malloc.h>
#include <unistd.h>
#include <memory.h>
#define MB 1024 * 1024
int main() {
    while (1) {
        void *p = malloc( 100*MB );
        memset(p,0, 100*MB );
        sleep(1);
    }
}

EDIT
OK, tested and updated.

share|improve this answer
add comment

There's a utility called stress which does this, among other things. apt-get install stress from Debian.

share|improve this answer
add comment

You could use mprime, which is, IIRC, a linux port of Prime95 of overclocking fame. mprime (and Prime95) will allow you to stress test the memory and CPU of your computer system. In addition, you can specify exactly how much memory you want mprime to use (to overflow into swap space, if you like).

Find mprime and prime95 here. I apologize in advance for the state of the website's navigation.

share|improve this answer
add comment

eatmemory is a very simple program that we use to test low memory conditions on DB servers I Hope it works for you

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.