简体   繁体   English

execve:将execve调用转换为fork

[英]execve : convert execve call to fork

I have an execve system call to overlay my curernt program with another one. 我有一个execve系统调用,将我的currnt程序与另一个程序叠加。 The code works fine but I my requirement is to change this execve system call with fork system call. 代码工作正常,但我的要求是使用fork系统调用更改此execve系统调用。 I am trying something like below: 我正在尝试以下内容:

pid_t child_pid;
child_pid = fork();
if(child_pid == 0) {
       if (-1 == execve(...)) //Normal previous execve call
       {
          .............
       }
}
else
{ //fork parent process
exit(0);
}

I am not sure that when we are replacing an execve system call by fork what things we should take care. 我不确定在用fork替换execve系统调用时应该注意些什么。 In my child process I am calling the existing execve call to let the original flow be maintained (as if without fork) but what should the parent do - should I normally exit or I need to wait for the child process to exit/die. 在我的子进程中,我正在调用现有的execve调用以保持原始流(就像没有fork一样),但是父级应该怎么做-我应该正常退出还是需要等待子进程退出/死亡。 The execve call overlays the current process with a new one so there is no question of parent / child process. execve调用在当前进程上覆盖了一个新进程,因此没有父/子进程的问题。

That's up to you. 随你(由你决定。 If you don't need to wait around, then you can just exit in which case the child process will become orphaned. 如果您不需要等待,则可以退出,在这种情况下,子进程将变为孤立的。

If the exit status of the child needs to be known, or if there is some operation to be performed after the child process exits, call wait() in the parent. 如果需要知道子进程的退出状态 ,或者在子进程退出需要执行某些操作,请在父进程中调用wait()

If there is no need for either of the above, you can exit the parent process. 如果不需要以上任何一种,则可以退出父进程。 The orphaned process will be re-parented by init , and hence will have no adverse effects. 孤立的进程将通过init进行重新父代化,因此不会产生任何不利影响。

 should I normally exit or I need to wait for the child process to exit/die

It depends on you, and your requirements, if needed you can wait for child process using wait(...), have a look at http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fapis%2Fwait.htm 这取决于您和您的要求,如果需要,您可以使用wait(...)等待子进程,请访问http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp ?topic =%2Fapis%2Fwait.htm

Also have a look at http://linux.die.net/man/2/fork 也可以看看http://linux.die.net/man/2/fork

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM