In this previous question I posted most of my own shell code. My next step is to implement foreground and background process execution and properly wait for them to terminate so
You may use:
if(!background) pause();
This way, the process blocks until it receives the SIGCHLD signal, and the signal handler will do the wait stuff.
SIGCHLD