关于 execlp()和 waitpid()的一个问题
資深大佬 : zxCoder 6
我在读一个 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 errorn"); } } } 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)