#include #include #include #include #include int main (int argc, char** argv) { // Basic check for proper calling arguments. if (argc != 3) { fprintf( stderr, "Usage: %s MEMORY(MB) SLEEP-TIME(s)\n", argv[0] ); return 1; } errno = 0; size_t size = strtol( argv[1], 0, 10 ); if( errno != 0 ) { fprintf( stderr, "error parsing memory: %s\n", strerror(errno) ); return 1; } unsigned int sleep_time = atoi( argv[2] ); // On linux there seems to be a limit per allocation of less than 0x76000000 // per allocation so try allocating two separate. size *= 512*1024; printf( "allocating: %lu (0x%lX)\n", size, size ); void * ptr1 = malloc(size); if( ! ptr1 ) { printf( "Failed to allocate %lu bytes: %s\n", size, strerror(errno)); return 1; } printf( "allocating another: %lu (0x%lX)\n", size, size ); void * ptr2 = malloc(size); if( ! ptr2 ) { printf( "Failed to allocate %lu bytes: %s\n", size, strerror(errno)); return 1; } printf( "sleeping for %u\n", sleep_time ); sleep( sleep_time ); printf( "running system command\n" ); int system_result = system( "echo system command" ); if ( system_result == -1 ) { fprintf( stderr, "Failed to execute shell: %s\n", strerror(errno) ); } else if ( system_result != 0 ) { fprintf( stderr, "Shell exited with status=%i\n", system_result ); } free(ptr1); free(ptr2); return 0; }