Angus, I think you should change the continue into a break, otherwise you won't 'move on' at all ;).
remove_it = true; } else if (waitrpid == 0) { // Still running. Move on to the next child. continue; } else if (WIFEXITED(stat_loc)) { // Ok, the return value goes into retval. Thanks, Alfredo