#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
usingnamespace std;
void test()
{
int pid = 0;
int w = -2;
int status = 0;
cout << "pid = " << pid << endl;
pid = fork();
if( pid == 0 ){
cout << "pid Son = " << pid << endl;
for( int i = 0; i < 100; i++ ) system("./SPheno LesHouches.in");
}
else {
clock_t t1, t2;
t1 = clock();
cout << "Father process" << endl;
cout << "pid father = " << pid << endl;
cout << "t1 = " << t1 << endl;
do {
t2 = clock();
float tdiff = (float)t2 - (float)t1;
cout << "t2 = " << t2 << " diff = " << tdiff << endl;
w = waitpid(pid, &status, WUNTRACED | WCONTINUED);
if (w == -1) {
perror("waitpid");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("exited, status=%d\n", WEXITSTATUS(status));
} elseif (WIFSIGNALED(status)) {
printf("killed by signal %d\n", WTERMSIG(status));
} elseif (WIFSTOPPED(status)) {
printf("stopped by signal %d\n", WSTOPSIG(status));
} elseif (WIFCONTINUED(status)) {
printf("continued\n");
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}
return;
}
Unfortunately I get only 1 printout of t2, the waitpid stopping the process. Is there a way to resume each time the child process ? I don't want only to wait that the child process be finished, but also to monitor the time it needs.