Clocking proccesses' time

babis85_at_gmail.com
Date: 11/27/05


Date: 27 Nov 2005 13:21:43 -0800

Hello guys, i have this part of code and i want to compute the time of
processes A, B and C :

/* process A */
pid_t pid1, pid2, pid;
struct rusage ru1, ru2;

pid1 = fork();
if (pid != 0) {/* parent process */
       pid2 = fork();
       if (pid2 != 0) {/* parent process */
               pid = waitpid(-1, &status, 0);
               getrusage(RUSAGE_CHILDREN, &ru1);
               waitpid(-1, &status, 0);
               getrusage(_CHILDREN, &ru2);

               if (pid == pid1) {
                       printf("B took time...\n", ru1.ru_utime.tv_sec);
                       printf("C took time...\n", ru2.ru_utime.tv_sec);

               } else {
                       printf("C took time...\n", ru1.ru_utime.tv_sec);
                       printf("B took time...\n", ru2.ru_utime.tv_sec);
               }
               getrusage(RUSAGE_SELF, &ru);
               printf("A took overall time...\n", ru.ru_utime.tv_sec);

       } else {
               /* process C */
               execp(...);
       }

} else {
       /* process B */
       execp(...);
}

The question is : Do i compute the time of each process successfully?
I get shorter time for proccess A than for its children... Isn't it
peculiar?Why?
I think that the time for proccess B is right, but i wonder if the next
call of getrusage adds c's time over b's. Do anyone know sth about
that?
Thanks a lot...


Quantcast