#include #include #include #include #include #include void usage() { std::cout << "Usage: dirty_ram \n"; exit(1); } int main(int argc, char **argv) { if (argc != 2) usage(); size_t mb; std::istringstream argin(argv[1]); argin >> mb; if (!argin) usage(); size_t size = mb * 1048576; void *buf = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (buf == MAP_FAILED) { perror("mmap"); return 1; } memset(buf, 1, size); return 0; }