#include #include #include #include #include #include #include #include #include #include #include void do_nothing(int sig) { } int main(int argc, char *argv[]) { char buf[4096]; int res, ppid; struct sigaction act; srand(time(NULL)); act.sa_handler = do_nothing; act.sa_flags = SA_RESTART; sigaction(SIGTERM, &act, NULL); switch (fork()) { case -1: printf("[parent] fork() failed: %s", strerror(errno)); break; default: printf("[parent] child created, making files...\n"); for (;;) { snprintf(buf, sizeof(buf), "leak.%08x", (unsigned int)rand()); printf("open '%s'...\n", buf);fflush(stdout); if ((res = open(buf, O_WRONLY|O_CREAT, 0666)) < 0) { perror("open()"); } close(res); } printf("[parent] exiting -- whoops? I should've been killed...\n"); break; case 0: printf("[child] repeatedly killing parent\n"); ppid = getppid(); for (;;) { if (kill(ppid, SIGTERM) < 0) { printf("[child] failed to kill parent, exiting...\n"); break; } usleep(10000L); } break; } return 0; }