Hi everybody,
I'm trying to understand how a parent and child processes interact.
This function( below) basically measures the fork time from the perspective of the parent only.
what i would like to know is how to measure the time from the perspective of parent and child (ie: inserting the GETTIME(endt) inside the child).
Any help would be appreciated.
void run_tests(int nt)
{
struct timeval begt;
struct timeval endt;
double secs;
int i;
pid_t pid;
int waitid;
int status;
double max_secs = 0.000000;
double min_secs = 0.000000;
double average = 0.000000;
double sum = 0.000000;
for(i=0; i<nt; i++)
{
GETTIME(begt); // gettimeofday()
if((pid = fork()) < 0)
{
perror("fork() failed!\n");
_exit(1);
}
if( pid == 0)
{
_exit(0);
}
waitid = wait(&status);
GETTIME(endt); // gettimeofday()
secs = TOTALSECS(begt,endt);
max_secs = max(secs,max_secs);
min_secs = min(secs,min_secs);
sum += secs;
printf("%2d: secs = %.6f\n", i,secs);
} /* end of FOR loop */
average = sum / (i + 1);
printf("min: %.6f\n", min_secs);
printf("max: %.6f\n", max_secs);
printf("sum: %.6f\n", sum);
printf("average: %.6f\n", average);
printf("waitid: %d \n", waitid);
printf(" \n");
}