#include #include /* Program to request megs of RAM to demo malloc ============================================= Compile with no flags to allow up to 900 megs. cc -Ae -o mallocmax mallomax.c Compile with -Wl -N to allow up to 1700 megs. cc -Ae -Wl -N -o mallocmax mallocmax.c Use "chatr +q3p enable" to increase to about 2700 megs: chatr +q3p enable mallocmax and chatr +q4p enable mallocmax to reach 3700 megs. The chatr option works with 11.11 and with several patches, with 11.0. Does not apply to anything earlier. Compile with +DA2.0W or +DD64 to create a 64bit program. With a 64-bit program, only the kernel parameter maxdsiz_64 (and swap) will limit the total malloc area: cc -Ae +DD64 -o mallocmax mallocmax.c */ main(int argc, char **argv) { pid_t mypid; char *m; int i,j,chunk; for(i=1; i<=4096; i++) { chunk=100*1024*1024; m=malloc(chunk); if(m) { printf("Malloc of %d Meg succeeded. Address %P. \n",100*i,m); } else { for(j=0;j<5;j++) { sleep(1); if( (m=malloc(chunk)) != 0) break; } if(m == 0){ printf("malloc of %d Meg failed.\n",i*100); break; } else { printf("malloc of %d Meg succeeded after %d sec sleep.\n",i*100,j+1); } } } mypid = getpid(); fprintf(stdout, "PID = %d, press to continue...",mypid); getchar(); }