For my school assignment, my professor wants me to store the state of background processes that i've made with my program and stored in a process table with each process entry being either "in progress" or "completed". To check whether a process has been completed(terminated) my professor needs me to use waitpid() to do this.
I don't know how this can be done because if i loop through all the processes i've created in the background(a bunch of sleep()'s) and i check each process by checking if waitpid() with each process's id as an argument to waitpid() and it return something other than -1(not an error), then each process will jump to the foreground when i really just want to know if that process is terminated or not.
Professor's original question:
BACKJOBS: A command that prints a list of background jobs and their current status. This feature is similar to the jobs command when using tcsh. The current status (i.e., in progress or completed) of each job can be determined by using the waitpid system call (see man waitpid for more information). The calls that report an error will be those that have already completed, so their status will be “completed”. The calls that do not result in an error will have a status of “in progress”.