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;
}
ここで述べたように「」を追加しようとしました:http set follow-fork-mode child
://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2006-02/msg00435.html
1.コードセクションをどこでデバッグするにはどうすればよい(0==pid)
ですか?
2. waitステートメントに到達すると、デバッガーはすぐに戻ります。wait()は、子が戻るまで中断することを想定していませんか?なぜすぐに戻るのですか?