小编Mat*_*ias的帖子

等待(状态),WEXITSTATUS(状态)总是返回0

我正在研究使用 fork() exec() wait() 的 ac 程序。第一个进程有这个代码:

int main(int argc, const char * argv[]) {
// insert code here...

int pid = fork();

if(pid == 0){
    //we are the child process.
    execlp("/Users/matthewdunn/Library/Developer/Xcode/DerivedData/PA2-hekivoaqvsegnggdvcfguasystig/Build/Products/Debug/Checker", "Checker", "1", "5", (char*) NULL);
}else{
    //we are the parent process.
    printf("Coordinator: forked process with ID ");
    printf("%d\n", pid);

    printf("Coordinator: waiting for process [");
    printf("%d", pid);
    printf("]\n");

    int status;
    waitpid(pid, &status, 0);
    int returned = WEXITSTATUS(status);

    printf("Coordinator: child process ");
    printf("%d", pid);
    printf(" returned ");
    printf("%d", returned);
    printf(".\n"); …
Run Code Online (Sandbox Code Playgroud)

c unix

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

unix ×1