Re: Swap priorities with swapon (Is my swap drive working?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



From: James Bensley <jwbensley@xxxxxxxxx>
> > But probably someone will come up with a small c program which eats all
> > available memory :)
> I would be interested  in such a program if anyone has one or a mega
> bash script that can achive the same?

Quick, dirty and unoptimized (and barely tested, might not work past 4GB)... ^_^

- - - - - -8<- - - - - - - - - - - -8<- - - - - - - - - - - -8<- - - - - -
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {

    FILE *fs;
    int i;
    long j;
    int mem_total;
    int mem_free;
    int mem_buffered;
    int mem_cached;
    int mem_to_fill;
    char *megabuff[1024];

    fs = fopen("/proc/meminfo", "r");
    fscanf(fs, "%*s %d %*s\n", &mem_total);
    fscanf(fs, "%*s %d %*s\n", &mem_free);
    fscanf(fs, "%*s %d %*s\n", &mem_buffered);
    fscanf(fs, "%*s %d %*s\n", &mem_cached);
    fclose(fs);

    mem_to_fill = (mem_free+mem_buffered+mem_cached+1024)*sizeof(char);
    printf("Filling %dKB...\n", mem_to_fill);
    for (i=0; i<1024; i++) {
        if ((megabuff[i] = malloc(mem_to_fill)) == NULL) {
            fprintf(stderr, "malloc error...");
        } else {
            for (j=0; j<mem_to_fill; j++) {
                megabuff[i][j] = '1';
            }
        }
    }
    for (i=0; i<1024; i++) {
        free(megabuff[i]);
    }
}

- - - - - -8<- - - - - - - - - - - -8<- - - - - - - - - - - -8<- - - - - -

Then swapoff /dev/..; swapon /dev/... to clean...

JD


      

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux