Clocking proccesses' time

Discussion in 'C Programming' started by babis85@gmail.com, Nov 27, 2005.

  1. Guest

    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...
     
    , Nov 27, 2005
    #1
    1. Advertising

  2. Michael Mair Guest

    wrote:
    > 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();

    <snip!>
    >
    > 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?


    fork(), thread, child processes etc. are not topical to comp.lang.c,
    thus you cannot rely on getting the best/good advice on that here.
    comp.unix.programmer or similar may be a better place to ask.

    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
     
    Michael Mair, Nov 27, 2005
    #2
    1. Advertising

  3. Jack Klein Guest

    On 27 Nov 2005 10:08:50 -0800, wrote in comp.lang.c:

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


    The problem here is that your question is not about the C language,
    but about non-standard, system-specific extensions.

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


    None of fork(), waitpid(), getrusage(), or execp() are standard C
    library functions, although I imagine they are all POSIX.

    You need to ask in a platform specific group. Since you posted via
    Google, the headers do not reveal your platform, so I can only suggest
    either news:comp.os.linux.development.apps or
    news:comp.unix.programmer.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Nov 27, 2005
    #3
  4. Guest

    Ok, then , sorry for that and thanks for the advice.
     
    , Nov 27, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yves Tchapda

    Boundary scan clocking

    Yves Tchapda, Sep 17, 2003, in forum: VHDL
    Replies:
    0
    Views:
    544
    Yves Tchapda
    Sep 17, 2003
  2. Ralf Hildebrandt

    clocking on a variable

    Ralf Hildebrandt, Jun 19, 2004, in forum: VHDL
    Replies:
    0
    Views:
    446
    Ralf Hildebrandt
    Jun 19, 2004
  3. Replies:
    1
    Views:
    833
  4. Replies:
    2
    Views:
    464
    Ralf Hildebrandt
    Jun 17, 2006
  5. Robin
    Replies:
    2
    Views:
    99
    Alexey V.Zelenin
    Dec 11, 2003
Loading...

Share This Page