Clocking proccesses' time

babis85_at_gmail.com
Date: 11/27/05

  • Next message: Mr. Uh Clem: "Re: effective user id"
    Date: 27 Nov 2005 13:21:54 -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 */
                   execlp(...);
           }

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

    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...


  • Next message: Mr. Uh Clem: "Re: effective user id"

    Relevant Pages

    • Clocking proccesses time
      ... pid_t pid1, pid2, pid; ... struct rusage ru1, ru2; ... I get shorter time for proccess A than for its children... ...
      (comp.lang.c)
    • Clocking proccesses time
      ... pid_t pid1, pid2, pid; ... struct rusage ru1, ru2; ... I get shorter time for proccess A than for its children... ...
      (comp.unix.programmer)
    • Re: SAFEARRAY* & COM Interop
      ... public class PID: IPID ... Is the retval a VARIANT* or a SAFEARRAY*? ... lifetime pid1 is valid also. ... Unhandled exception at 0x7c81eb33 in MFCWSTestApp.exe: ...
      (microsoft.public.dotnet.languages.vc)
    • Re: Clocking proccesses time
      ... pid_t pid1, pid2, pid; ... pid1 = fork(); ... I get shorter time for proccess A than for its children... ... 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. ...
      (comp.lang.c)
    • Re: Clocking proccesses time
      ... pid1 = fork(); ... The if condition needs to be checking for pid1 and not pid. ...
      (comp.unix.programmer)