/** Forks and executes the required number of processors. */ static void start_processors(void) { int i, pid; char proc_id[8], nsems[8]; if(itoa((2 * processors) + 2, nsems, 8) == -1) { write_to_fd(2, "Failed to convert number of semaphores\n"); kill_group(SIGTERM); } for (i = 0; i < processors; ++i) { pid = fork(); if (pid == -1) { write_to_fd(2, "Failed to fork processor\n"); kill_group(SIGTERM); } if (pid == 0) { if(itoa(i, proc_id, 8) != -1) execl("processor.x", "processor.x", proc_id, nsems, (char *) NULL); kill_group(SIGTERM); } } }
void kill_groups(state *s) { int prisoners; int misses = 0; int i = 0; while (misses < 2 && i++ < NUM_MAX_KILLS) { if (kill_group(s)) { misses = 0; } else { make_move(s, 0, &prisoners); misses++; } } }