#include #include #include #include int main(int argc,char** argv) { unsigned long chunk_size = 0; char* p = 0; int sleep_time = 0; if (argc != 3) { fprintf(stderr,"Usage: memalloc bytes_to_alloc sleep_time\n"); exit(1); } chunk_size = (unsigned long)atol(argv[1]); sleep_time = atoi(argv[2]); if (!(p=(char*)malloc(chunk_size))) { fprintf(stderr,"Error allocating %lu bytes\n", chunk_size); exit(1); } printf("Allocation successful, sleeping for %d seconds\n", sleep_time); sleep(sleep_time); printf("Initializing %lu bytes\n", chunk_size); memset(p,0,chunk_size); printf("Initalization successful, sleeping for %d seconds\n", sleep_time); sleep(sleep_time); printf("Freeing memory\n"); free(p); printf("Memory freed\n"); return 0; }