#include <stdio.h> #include <signal.h> #include <sys/types.h> #include <sys/mman.h> #include <fcntl.h> #define CHILDREN 500 #define ITERATIONS 20 #define SIGITERATIONS 20 int *procs; int sigary[] = {2, 3, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 0}; void catch_sig(); int sid; main() { int i, iter, j, pid, k, l, m, size, fd; size = CHILDREN * 4; fd = open("/dev/zero", O_RDWR); procs = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); bzero(procs, size); for (i = 0; sigary[i] > 0; i++) signal(sigary[i], SIG_IGN); sid = getsid(); sid += 1000; setsid(sid); for (iter = 1; iter <= ITERATIONS; iter++) { for (i = 0; i < CHILDREN; i++) { if ((pid = fork()) == 0) { for (k = 0; k < SIGITERATIONS; k++) for (m = 0; sigary[m] > 0; m++) sigsend(P_SID, sid, sigary[m]); exit(0); } else if (pid == -1) { printf("Could fork only %d processes\n",i); break; } else procs[i] = pid; } printf("Iteration %d, started %d children.\n",iter, i); for (j = 0; j < i; j++) wait((int *) 0); } } void catch_sig(sig) int sig; { signal(sig, catch_sig); }