Unix Programming - Clocking proccesses' time

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2005 > Clocking proccesses' time





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Clocking proccesses' time
babis85@gmail.com

2005-11-27, 5:53 pm

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

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com