0

dup2 と複数のスレッドに関する非常に文字列の問題に遭遇しました。コードは次のようになります。

pipe out, err;
int forkpid = fork();

if (forkpid == 0) {
    dup2(out.writeFd, STDOUT_FILENO);
    dup2(err.writeFd, STDERR_FILENO);
    printf("hello\n");
}

do {
    int res = poll(&fds, 2, 200);
    if (res) {
        for (int i = 0; i < 2; i++) {
            bytes = read(fds[i].fd, buff, size);
            if (fds[i].fd == out.readFd)
                printf("out\n");
            if (fds[i].fd == err.readFd)
                printf("err\n");
        }
    }
} while(....);

別のプロジェクトでコードをテストしたところ、「hello」が std から出力されていることがわかりますが、大きなプロジェクトに配置すると、「hello」が err:( から出力されます。

私は xcode5.0 を使用しており、c++ と目的の c を混在させています。これについて何か考えはありますか?ありがとう

4

1 に答える 1