Skip to content

Instantly share code, notes, and snippets.

@MosheBerman
Created May 24, 2013 21:34
Show Gist options
  • Save MosheBerman/5646676 to your computer and use it in GitHub Desktop.
Save MosheBerman/5646676 to your computer and use it in GitHub Desktop.
/*
* Loop through the processes and wait for them
* to terminate. Then print the childid, and the
* the pid.
*/
int status = NULL;
for (int i = 0; i < n; i++)
{
/* Wait for the child process
* and grab it's status info
*/
status = NULL;
/* Wait for the first process
* that terminates to do so.
*/
waitpid(-1, &status, 0);
int childid = -1;
if(WIFEXITED(status))
{
childid = WEXITSTATUS(status);
/* Log the results
*/
time = elapsedTime(1);
printf("%li: Child %i, pid = %i, terminated\n", time, childid, PIDs[childid]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment