关于c/c++里的exec系列函数调用的问题~~~在线等
请教下,关于exec系列函数,调用成功的时候不返回值,失败才返回-1,那这样的话程序一直没结束了啊?
比如有这样一段程序test.cpp:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main( void )
{
int pid = fork();
if(pid == 0){
int status = execl("/bin/ls", "ls", "-l", (char * )0);
cout << "执行结果status : " << status << endl;
}else {
int task_id = pid;
cout << "PID : " << task_id << endl;
}
}
在unix下g++ test.cpp -o test
然后执行test,程序执行完ls -l命令后,就一直不会返回命令提示符$了,也找不到这个进程。。
请问这应该怎么解决啊???急~~~在线等高人解答~~~