【发布时间】:2013-03-17 22:43:41
【问题描述】:
我正在尝试使用 eclipse cdt (Juno) 调试一些 fork() 机制。 我用 C 编写了程序。
if( -1 == (pid = fork()) ) /* error */
goto cleanup;
else if ( 0 == pid ) /* child */
{
execlp("gcc", "gcc", cFilePath, "-o" , GCC_OUTPUT_FILE_NAME, NULL);
goto cleanup; /* Arrives here only on error! */
}
else if (pid > 0) /* parent - checks: correct pid returns, returns normally, with exit status = 0*/
{
returnedpid = wait(exitStatus);
if( pid != returnedpid || exitStatus == NULL || !WIFEXITED(*exitStatus) || !WEXITSTATUS(*exitStatus) )
goto cleanup;
}
我尝试在这里添加“set follow-fork-mode child”:http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2006-02/msg00435.html
1.如何调试(0==pid)所在的代码段?
2。当我到达等待语句时,调试器立即返回,不是 wait() 假设暂停直到孩子返回吗?为什么会立即返回?
【问题讨论】:
标签: c eclipse gdb fork eclipse-cdt