I have a Makefile that looks something like this:
sometarget:
command_one # calls fork()
command_two
Here’s the problem I’m running into when I do make sometarget:
-
command_onestarts and eventually callsfork(). -
The child process
execs something and finishes early, returning control tomakebefore all the processing ofcommand_oneis done. -
command_twothen executes before the parent completes, causing the sequence to fail (as it depends oncommand_onefinishing completely).
I can change command_one (the fork() and exec() have to stay, though), and I’d rather not change the Makefile if possible. Is there a way to prevent the child process from returning (on Linux)? I’m thinking the answer is no, but I’ve been wrong before…
It sounds like your
command_onelooks something like this pseudo-code:If you insert a
waitpid(2)orwait(2)(or any member of the family) immediately before the parent’sexit, it’ll make sure both child and parent are finished beforemake(1)moves onto the next command. It’ll look something more like this: