#include #include #include #include #include int main() { int cnt_success = 0, cnt_failure = 0; int status; void *addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (addr == MAP_FAILED) { perror("mmap failed"); exit(1); } if (mprotect(addr, 4096, PROT_READ | PROT_WRITE | PROT_EXEC) == -1) { perror("mprotect failed"); exit(1); } if (madvise(addr, 4096, MADV_DONTFORK) == -1) { perror("madvise failed"); exit(1); } printf("VMA created at address %p\n", addr); for (int i = 0; i < 10000; i++) { pid_t pid = fork(); if (pid == -1) { cnt_failure++; } else if (pid == 0) { exit(EXIT_SUCCESS); } else { cnt_success++; wait(&status); if (status != 0) { fprintf(stderr, "Bad wait status: 0x%x\n", status); exit(2); } } } printf("success:%d failure:%d\n", cnt_success, cnt_failure); return 0; }