#include #include #include #include #include #include static pid_t engine_pid = 0; static pid_t client_pid = 0; static void cleanup(int sig) { (void)sig; if (engine_pid > 0) kill(engine_pid, SIGTERM); if (client_pid > 0) kill(client_pid, SIGTERM); while (wait(NULL) > 0); _exit(0); } int main(int argc, char *argv[]) { signal(SIGINT, cleanup); signal(SIGTERM, cleanup); engine_pid = fork(); if (engine_pid == 0) { execl("./engine/looper", "looper", NULL); perror("execl engine"); _exit(1); } client_pid = fork(); if (client_pid == 0) { if (argc > 2 && strcmp(argv[1], "-s") == 0) { execl("./client/looper-client", "looper-client", "-s", argv[2], NULL); } else { execl("./client/looper-client", "looper-client", NULL); } perror("execl client"); _exit(1); } int status; pid_t exited = wait(&status); if (exited == engine_pid) { kill(client_pid, SIGTERM); wait(NULL); } else if (exited == client_pid) { kill(engine_pid, SIGTERM); wait(NULL); } return 0; }