xcode 7.2.1版(7C1002)上的why wait()返回-1

xcode 7.2.1版(7C1002)上的why wait()返回-1,xcode,macos,fork,wait,errno,Xcode,Macos,Fork,Wait,Errno,伙计们,我有下面的c代码: #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <errno.h> int main (int argc, char *argv[]) { int exit; pid_t tc_pid, ret_pid

伙计们,我有下面的c代码:

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>


int main (int argc, char *argv[])
{
    int exit;
    pid_t tc_pid, ret_pid;
    tc_pid = fork();
    if(tc_pid != 0){
        ret_pid = wait(&exit);
        printf("parent process done, tc_pid = %d, ret_pid = %d, errno = %d\n", tc_pid, ret_pid, errno);
        fflush(stdout);
    }
    printf("parent process done, tcpid = %d, my_pid = %d\n", tc_pid, getpid());
    fflush(stdout);

    return 0;
}
其中wait()的返回值为-1(如果正确,则应为74377),errno为-4

但是,当我使用在终端中运行的相同代码(我使用zsh)时,输出为:

parent process done, tcpid = 0, my_pid = 74419
parent process done, tc_pid = 74419, ret_pid = 74419, errno = 0
parent process done, tcpid = 74419, my_pid = 74418
这就是我想要的。有人知道为什么会这样吗?谢谢各位

我的OSX是10.11.3,我的机器是MBPR 2015年初的xcode 7.2.1,
gcc 4.2.1,苹果LLVM版本7.0.2(clang-700.1.81),目标:x86_64-Apple-darwin15.3.0,线程模型:posix根据
errno.h
,4的errno是
EINTR
,其中:

呼叫被捕获的信号中断或信号未设置SA_重新启动标志。


显然,您正在使用一个信号获取
等待
退出。也许你需要重新思考一下,你到底想在这里做什么,有没有一种不使用
wait
的方法呢?

嗨,Michael,谢谢你的回答,我只是想看看fork()是如何工作的,wait()是如何工作的。问题是在gcc中,输出是正确的,而在xcode中则不是,为什么会发生这种情况,xcode会向进程发送一个中断信号?
parent process done, tcpid = 0, my_pid = 74419
parent process done, tc_pid = 74419, ret_pid = 74419, errno = 0
parent process done, tcpid = 74419, my_pid = 74418