Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于第0章中代码的疑问。 #54

Open
neil-chennn opened this issue Feb 21, 2017 · 2 comments
Open

关于第0章中代码的疑问。 #54

neil-chennn opened this issue Feb 21, 2017 · 2 comments

Comments

@neil-chennn
Copy link

在第0章第一段关于fork()的代码中

int pid;
pid = fork();
if(pid > 0){
    printf("parent: child=%d\n", pid);
    pid = wait();
    printf("child %d is done\n", pid);
} else if(pid == 0){
    printf("child: exiting\n");
    exit();
} else {
    printf("fork error\n");
}

按照此代码写出的程序,运行结果为

parent: child=3610
child: exiting
child -1 is done

将其中的 wait() 修改为 wait(NULL)后,结果正确。

@neil-chennn
Copy link
Author

我真实遇到这个问题了,新手,google了很多才解决掉。不知道是我操作错误,还是真的存在这个问题。

@ghost
Copy link

ghost commented Feb 21, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant