The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-09-2008 08:22 PM
display in a child process a command called in the parent one remid1985 High Level Programming 7 01-19-2007 02:40 PM
Parent/Child Processes yoi2hot4ya Shell Programming and Scripting 2 05-31-2006 10:27 AM
Parent/Child Scripting logic Question jigarlakhani Shell Programming and Scripting 3 11-30-2005 08:35 PM
Implementing 2 pipes between a parent and child process bwgoudey High Level Programming 2 09-24-2005 08:14 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-16-2005
Registered User
 

Join Date: Feb 2005
Posts: 1
Question parent and child process question?

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.

HTML Code:
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");

}
Reply With Quote
Google UNIX.COM
Forum Sponsor
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0