Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making parent process wait till child has called exec

Tags:

linux

fork

In linux, after calling fork(), my child process is going to call exec soon. Is there a way for the parent process to wait() and not do anything till the child has exec'ed?

Thanks.

like image 722
MK. Avatar asked Dec 09 '25 23:12

MK.


1 Answers

There is no (API) way for the parent to know that the child is performing an exec().

But there is a nice pipe-trick: have the child inherit a filedescriptor (for a pipe) and (before the fork() ) set the close-on-exec flag for the pipe. The parent will be notified by an EOF on the pipe when it is closed by the exec().

Please note that this does not need any collaboration from the child.

like image 99
wildplasser Avatar answered Dec 11 '25 14:12

wildplasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!