I have achieved this in the past by running the "original" code in the "child" and the "spawned" code in the "parent" (that is: you reverse the usual sense of the test after fork()
). Then trap SIGCHLD in the "spawned" code...
May not be possible in your case, but cute when it works.