void genere_aleatoire_unique() { int nbetats; int nblettres; int numgraphe; int nb_succ, nb_init, nb_term; PFA A; cout << "Nombre d'Ètat : "; cin >> nbetats; cout << "Nombre de lettres : "; cin >> nblettres; cout << "Numero du graphe : "; cin >> numgraphe; cout << "nombre de successeurs par couple (etat-lettre) : "; cin >> nb_succ; cout << "nombre maximal d'etats initiaux : "; cin >> nb_init; cout << "nombre maximal d'etats terminaux : "; cin >> nb_term; A.becomeRandomMax (nbetats, nblettres, numgraphe, nb_succ, nb_init, nb_term); string fichier_ps = "_tmp.ps"; string fichier_tmp = "_temporary_file"; export_to_pdf (A, fichier_ps, fichier_tmp); show_ps (fichier_ps); if (A.isPFA ()) { if (A.isPRFA (true)) cout << "is PRFA" << endl; else cout << "is PFA" << endl; } else { cout << "not PFA" << endl; } }
int ns_init(int argc, char **argv) { struct sigaction sa = { .sa_handler = ns_sig_hand, .sa_flags = SA_RESTART, }; int ret, fd, status_pipe = STATUS_FD; char buf[128], *x; pid_t pid; bool reap; ret = fcntl(status_pipe, F_SETFD, FD_CLOEXEC); if (ret == -1) { fprintf(stderr, "fcntl failed %m\n"); exit(1); } reap = getenv("ZDTM_NOREAP") == NULL; sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask, SIGTERM); if (reap) sigaddset(&sa.sa_mask, SIGCHLD); if (sigaction(SIGTERM, &sa, NULL)) { fprintf(stderr, "Can't set SIGTERM handler: %m\n"); exit(1); } x = malloc(strlen(pidfile) + 3); sprintf(x, "%sns", pidfile); pidfile = x; /* Start test */ pid = fork(); if (pid < 0) { fprintf(stderr, "fork() failed: %m\n"); exit(1); } else if (pid == 0) { close(status_pipe); unsetenv("ZDTM_NEWNS"); return 0; /* Continue normal test startup */ } ret = -1; if (waitpid(pid, &ret, 0) < 0) fprintf(stderr, "waitpid() failed: %m\n"); else if (ret) fprintf(stderr, "The test returned non-zero code %d\n", ret); show_ps(); if (reap && sigaction(SIGCHLD, &sa, NULL)) { fprintf(stderr, "Can't set SIGCHLD handler: %m\n"); exit(1); } while (reap && 1) { int status; pid = waitpid(-1, &status, WNOHANG); if (pid == 0) break; if (pid < 0) { fprintf(stderr, "waitpid() failed: %m\n"); exit (1); } if (status) fprintf(stderr, "%d return %d\n", pid, status); } /* Daemonize */ write(status_pipe, &ret, sizeof(ret)); close(status_pipe); if (ret) exit(ret); /* suspend/resume */ test_waitsig(); show_ps(); fd = open(pidfile, O_RDONLY); if (fd == -1) { fprintf(stderr, "open(%s) failed: %m\n", pidfile); exit(1); } ret = read(fd, buf, sizeof(buf) - 1); buf[ret] = '\0'; if (ret == -1) { fprintf(stderr, "read() failed: %m\n"); exit(1); } pid = atoi(buf); fprintf(stderr, "kill(%d, SIGTERM)\n", pid); if (pid > 0) kill(pid, SIGTERM); ret = 0; if (reap) { while (ret != -1) ret = wait(NULL); } else { waitpid(pid, NULL, 0); } exit(1); }