如何从子进程读取返回代码

How to read the return code from a child process

本文关键字:返回 代码 读取 子进程      更新时间:2023-10-16

我使用fork和execv来执行子进程。在父程序中,我有这个:

int status;
wait(&status);
cout << "return code = " << status << endl;

将等待子进程终止,然后显示它的返回代码?

如果想获取指定子进程的状态,应该使用waitpid()。wait()将返回第一个完成子进程的状态

是的,从我读到的来看应该是http://linux.die.net/man/2/wait