I recently had a need to generate arbitrary memory usage with arbitrary binary names for a monitoring effort I was working on. My typical go-to for generating resource usage is the excellent stress utility, but this didn’t meet the arbitrary binary name criteria, and I’m pretty sure the memory workers it spins up just consume as much memory as possible.
So, I wrote a quick and dirty C program to do the job. My first attempt was a simple malloc(arbitrary_bytes) followed by a sleep (shut up, I said it was quick and dirty =D), but interestingly, the binary ran with almost no memory usage. The reason is apparently that while malloc allocates the requested memory, it doesn’t initialize it. Switching this call to calloc(num_elements, element_size) produced the desired behavior. Huzzah!