Rather than execve()'ing a second process when it is detected that pkg needs to be re-run, fork the process early-on, let the forked child run, and do whatever wrk is required and signal back to the parent by setting its exit status if it needs to be restarted.
Matthew Seaman