diff options
Diffstat (limited to 'hw2/judge.c')
-rw-r--r-- | hw2/judge.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/hw2/judge.c b/hw2/judge.c index 9c707a0..51c195b 100644 --- a/hw2/judge.c +++ b/hw2/judge.c @@ -40,10 +40,6 @@ static void player_tle_setter (int signo) { player_tle = 1; } -static void cleanup_child (int signo) { - waitpid (-1, NULL, WUNTRACED | WNOHANG); -} - static void fdata_clear (FData* d) { d->last = 0; d->score = 0; @@ -142,8 +138,6 @@ int main (int argc, char* argv[]) { }; sigemptyset (&sa.sa_mask); sigaction (SIGALRM, &sa, NULL); - sa.sa_handler = cleanup_child; - sigaction (SIGCHLD, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, NULL); @@ -203,6 +197,7 @@ int main (int argc, char* argv[]) { fprintf (stderr, "Cannot fork: %s\n", strerror (errno)); for (int j = 1; j < i; j++) { kill (ffd[i].pid, SIGKILL); + waitpid (ffd[i].pid, NULL, 0); } goto new_loop_end; } else if (ffd[i].pid == 0) { @@ -357,12 +352,19 @@ int main (int argc, char* argv[]) { } fflush (stdout); + /* clean up all child process */ + for (i = 1; i <= 4; i++) { + comp135_log (comp, "Waiting for PID %u to exit ...", ffd[i].pid); + kill (ffd[i].pid, SIGKILL); + waitpid (ffd[i].pid, NULL, 0); + } + + comp135_log (comp, "Waiting for the next request from big_judge"); + new_loop_end: free (linestr); linestr = NULL; linelen = 0; - - comp135_log (comp, "Waiting for the next request from big_judge"); } free (linestr); |