diff options
author | LAN-TW <lantw44@gmail.com> | 2013-11-16 17:06:29 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-11-16 17:06:29 +0800 |
commit | 0a2f61bc3b40a26fb192555f404a32f206d112a4 (patch) | |
tree | 00484198e3b3a6078a4f80af4682fe5ba23cb162 /hw2/judge.c | |
parent | 69ac4b3704e5360c7e67903dbfa9e0780bffa040 (diff) | |
download | sp2013-0a2f61bc3b40a26fb192555f404a32f206d112a4.tar.gz sp2013-0a2f61bc3b40a26fb192555f404a32f206d112a4.tar.zst sp2013-0a2f61bc3b40a26fb192555f404a32f206d112a4.zip |
HW2: big_judge 成績排序、judge 砍掉未結束的 player
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); |