C++中执行shell命令,popen与system的区别_c++ popen_Op_chaos的博客-CSDN博客
2.system
system()函数执行过程:
1.fork一个子进程;
2.在子进程中调用exec函数去执行command;
3.在父进程中调用wait去等待子进程结束。
由于system没有新开shell,执行system的随后会调用waitpid,来等待子进程运行完毕,所以会阻塞的。
———————————
#include<stdlib.h>
#include <stdio.h>int main()
{system("./test");printf("exit\n");
}
kill -9 父进程
父进程退出,子进程不会退出.