我就遇到了這個問題,幾個小時前暢通。Linux下C,waitpid函數()由處理信號,返回值-1,並將errno 5
即使我有固定的,我只是不明白爲什麼會這樣。
signal(SIGHUP, sighupHandler);
.
.
.
// sync with child by getting a char written by child
fgetc(pipe_in);
close(pipe_in);
int status;
if(waitpid(initProcessPid, &status, 0) == -1){
printf("debug: errno is %d\n", errno);
printf("failed to wait for init process to end\n");
}
每次waitpid函數()塊中一個SIGHUP發生,waitpid函數()返回-1,並將errno 5.
雖然EINTR應該在錯誤號由ALK指出這種情況下,是EINTR 4,不是5
幾個小時收集來自gdb的想法,因爲我沒有真正在做什麼SIGHUP當前之後,我改變了我的代碼:
signal(SIGHUP, SIG_IGN);
然後它工作正常,SI GHUP不再打破waitpid()模塊。
我是工作在Linux容器,其目的是單個文件和靜態的。 https://github.com/Kethen/minicontainer
https://stackoverflow.com/q/41474299/2371524 –
來自['waitpid()'的POSIX文檔](http://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html) (Linux的手冊頁基本上是一樣的):「*** ERRORS ** 如果發生以下情況,waitpid()函數將失敗:[...] [EINTR] 函數被信號中斷。 ..]「*」 – alk
另外,不要使用'signal()',因爲它的語義不同;請務必使用['sigaction()'](http://man7.org/linux/man-pages/man2/sigaction.2.html)。另外,如果同時包含''和'',則可以使用'strerror(errno)'獲取可讀的錯誤字符串。 –