我在读一个 OJ 判题核心的代码,里面关于特判的代码,fork 了一个子进程,调用 execlp()去执行 spj,没有报错,但是父进程里 waitpid()就报错了,返回值是-1,错误码 10,no child processes,这是怎么回事
int status = 0;
pid_t pid_spj = fork();
if (pid_spj < 0) {
LOG_WARNING("error for spj failed, %d:%s", errno, strerror(errno));
output_result(judge_conf::OJ_SE, -errno, judge_conf::EXIT_COMPARE_SPJ_FORK);
exit(judge_conf::EXIT_COMPARE_SPJ_FORK);
} else if (pid_spj == 0) {
freopen(file_spj.c_str(), "w", stdout);
if (EXIT_SUCCESS == malarm(ITIMER_REAL, judge_conf::spj_time_limit)) {
log_close();
if (execlp((spj_path + "/" + problem::spj_exe_file).c_str(),
problem::spj_exe_file.c_str(), input_file.c_str(),
output_file.c_str(), output_file_std.c_str(), NULL) < 0) {
printf("spj execlp error\n");
}
}
} else {
//no child process
if (waitpid(pid_spj, &status, 0) < 0) {
LOG_BUG("waitpid failed, %d:%s", errno, strerror(errno));
output_result(judge_conf::OJ_SE, -errno, judge_conf::EXIT_COMPARE_SPJ_WAIT);
exit(judge_conf::EXIT_COMPARE_SPJ_WAIT);
}
}
1
Nitroethane 2020-09-12 11:38:56 +08:00
错误码给你说了啊,没有子进程。waitpid 函数是父进程等待子进程的结束,如果返回 ECHILD,也就是 10,说明调用进程没有 PID 为 pid_spj 的子进程
|