35 int main (
int argc,
char **argv )
38 printf (
"Usage: ./rambrain-memeater <MB to leave free>\n" );
42 ifstream meminfo (
"/proc/meminfo", ifstream::in );
44 for (
int c = 0; c < 3; ++c ) {
45 meminfo.getline ( line, 1024 );
48 printf (
"%s\n", line );
51 char *begin = NULL, *end = NULL;
54 if ( *pos <= '9' && *pos >=
'0' ) {
55 if ( begin == NULL ) {
59 if ( begin != NULL ) {
66 mbytes_avail = atol ( begin ) / 1024;
67 long mbytes_holdfree = atoi ( argv[1] );
68 long mb_alloc = mbytes_avail - mbytes_holdfree;
70 printf (
"\nWe detected %lu free mBytes\nAllocating %lu\n", mbytes_avail, mb_alloc );
71 if ( mb_alloc <= 0 ) {
72 printf (
"You don't need to nomnom, we're already fed up." );
77 unsigned int chunkSize = 1024 * 1024;
79 void *malloced[mb_alloc];
80 for (
int c = 0; c < mb_alloc; ++c ) {
81 malloced[c] = malloc ( chunkSize );
82 for (
unsigned int d = 0; d < chunkSize; ++d ) {
83 ( (
char * ) malloced[c] ) [d] = 0x07;
86 mlockall ( MCL_CURRENT );
87 printf (
"Oink, **burpp**" );
int main(int argc, char **argv)
Provides a binary for a program which eats memory in order to decrease the system memory manually...