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-10-2008 12:22 AM
display in a child process a command called in the parent one remid1985 High Level Programming 7 01-19-2007 06:40 PM
Parent/Child Processes yoi2hot4ya Shell Programming and Scripting 2 05-31-2006 02:27 PM
Parent/Child Scripting logic Question jigarlakhani Shell Programming and Scripting 3 12-01-2005 12:35 AM
Implementing 2 pipes between a parent and child process bwgoudey High Level Programming 2 09-25-2005 12:14 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-16-2005
tosa tosa is offline
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");

}
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0