Jat*_*tiA 1 c linux fork exec child-process
我有简单的C程序,它使用fork()和execl()执行应用程序.如果execl()无法运行应用程序,那么我必须在父进程中调用一个函数并退出子进程.如果execl()成功运行应用程序,那么我已从父进程显示成功日志.因此,父进程应该等待子进程的execl()调用(只是调用,直到应用程序执行结束),获取有关其状态的一些信息,然后做出决策并继续自己的执行.这是我的代码.
int main()
{
int iExecRetVal, pid;
pid = fork();
if (pid == -1)
{
}
else if (pid > 0)
{
}
else
{
iExecRetVal = execl("./flute-static", "./flute-static", "-send", "-a192.168.190.1/6666", "JFlute.1.2.tar.gz", NULL);
if (iExecRetVal == -1)
{
/*execl() failed, need some error handling in the parent process*/
}
_exit(0);
}
/*Parent's normal execution*/
}
int HandleSuccessFromParent()
{
/*Should be called when exec call was successful*/
}
int HandleFailureFromParent()
{
/*Should be called when exec call was NOT successful*/
}
Run Code Online (Sandbox Code Playgroud)
我们知道execl()不会成功返回.因此,如何在子进程中执行execl()之后正确调用HandleSuccessFromParent()和HandleFailureFromParent()函数.请帮我.
| 归档时间: |
|
| 查看次数: |
1644 次 |
| 最近记录: |