PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : getrlimits und getrusage



Mat
21-10-2005, 12:53
Hallo ich versuche nun shcon seit stunden folgendes:

Ich will abwechselnd Speicherbereich alloziieren und immer mehr...das heißt erst alloziieren und wenn es geht dann wieder free......dann mehr speicher alloziieren bis es nicht mehr geht also bis die ressourcen aufgebrucht sind...

Allerdings schaffe ich das nicht mit getrlimit udn getrusage...
wobei getrusage bei mir nicht mal funzt. ???

Hier mein versuch:


#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>

static void limits( int resource ) {
struct rlimit l;

if( getrlimit( resource, &l ) < 0 ) {
printf("keine Angaben\n");
return;
}
printf("Soft-Limit: ");
(l.rlim_cur == RLIM_INFINITY)?
printf("kein Limit "):
printf("%ld ",l.rlim_cur);
printf("Hard-Limit: ");
(l.rlim_max == RLIM_INFINITY)?
printf("kein Limit\n"):
printf("%ld \n",l.rlim_max);

}

static void whos( int who ) {
struct rusage r;

getrusage(who, &r);

printf("%ld ",r.ru_isrss);
printf("%ld \n",r.ru_idrss);

}
static void malloc_mem()
{
int i = 0;
int iter = 0;
while(1)
{
int *p;
p = (int *)malloc(i * sizeof(long));
if (p == NULL || iter == 10000)
{
i /= 4000000; //getting Bytes for output
printf("\nMalloced:%d Mega-Bytes\n",i);
if (iter == 10000) printf("\nHalt due to iter maximum!!!!\n");
exit(0);
} else {
free(p);
iter = -1;
}

i += 100000000;
iter++;
}
}
int main( int argc, char *argv[] ) {
unsigned int i;

const int limit[] = {
RLIMIT_DATA,
RLIMIT_STACK,
};

const char *s_limit[] = {
"RLIMIT_DATA",
"RLIMIT_STACK",
};

/* const int who[] = {
ru_idrss,
ru_isrss,
};
const char *s_who[] = {
"integral unshared data size",
"integral unshared stack size",
};
*/

for( i = 0; i< sizeof(limit)/sizeof(long); i++) {
printf("%s = ",s_limit[i]);
limits( limit[i] );
}

/* for( i = 0; i< sizeof(who)/sizeof(long); i++) {
printf("%s = ",s_who[i]);
whos( who[i] );
}*/


malloc_mem();

return EXIT_SUCCESS;
}



weiß jemand wie man das sinnvoll hingebkommen könnte ?