copied forkexec and added a loop