小编Jim*_*ian的帖子

fork/exec/waitpid问题

我试图通过检查waitpid()的结果来确定执行是否失败.但是,即使我运行一个我知道失败的命令并将问题写入stderr,下面的检查也从未注册.这段代码可能有什么问题?

谢谢你的帮助.

pid_t pid;  // the child process that the execution runs inside of.
int ret;      // exit status of child process.

child = fork();

if (pid == -1)
{
   // issue with forking
}
else if (pid == 0)
{
   execvp(thingToRun, ThingToRunArray); // thingToRun is the program name, ThingToRunArray is
                                        //    programName + input params to it + NULL.

   exit(-1);
}
else // We're in the parent process.
{
   if (waitpid(pid, &ret, 0) == -1)
   {
      // Log an …
Run Code Online (Sandbox Code Playgroud)

c fork exec waitpid execvp

5
推荐指数
1
解决办法
8774
查看次数

标签 统计

c ×1

exec ×1

execvp ×1

fork ×1

waitpid ×1