C语言 wait(null) 和 wait(&status) C 语言和状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23092231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:00:12  来源:igfitidea点击:

wait(null) and wait(&status) C language and Status

cunixposixwaitstatus

提问by user3260388

What is the difference between wait(null)and wait(&status)in c system programming?

c 系统编程中wait(null)和 有什么区别wait(&status)

And what is the content of the pointer status ?

指针状态的内容是什么?

回答by user43968

If you call wait(NULL)(wait(2)), you only wait for any child to terminate. With wait(&status)you wait for a child to terminate but you want to know some information about it's termination.

如果您调用wait(NULL)( wait(2)),您只等待任何子进程终止。随着wait(&status)你等待孩子终止,但你要知道它的终端的一些信息。

You can know if the child terminate normally with WIFEXITED(status)for example.

例如,您可以知道孩子是否正常终止WIFEXITED(status)

statuscontains information about processes that you can check with some already defined MACRO.

status包含有关进程的信息,您可以使用一些已定义的宏进行检查。

回答by lahiruhashan

wait(NULL)will only wait until the child process is completed. But, wait(&status)will return the process id of the child process that is terminated.

wait(NULL)只会等到子进程完成。但是, wait(&status)将返回终止的子进程的进程 ID。

pid = wait(&status); // the information is returned