|
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 */
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...
| |
| budyanto.himawan@gmail.com 2005-11-29, 7:51 am |
| Is this snippets of the real code?
pid1 = fork();
if (pid != 0) {/* parent process */
The if condition needs to be checking for pid1 and not pid.
| |
| babis85@gmail.com 2005-11-29, 5:58 pm |
| When i was writing this code, i haven't got the prototype to look to.
But this is the code.
| |
| joe@invalid.address 2005-11-29, 5:58 pm |
| babis85@gmail.com writes:
> When i was writing this code, i haven't got the prototype to look to.
> But this is the code.
What code are you talking about?
Joe
--
Gort, klatu barada nikto
| |
| babis85@gmail.com 2005-11-30, 5:55 pm |
| To make myshelf clear :
When i posting this message i was to a remote computer. So i hadn't got
my already code
to post. So, i wrote this code, as far as i remembered, and post it.
That's why i had a mistake at the if statement.
The point is "Clocking time process". Do anyone know sth about that?
Thanks and sorry for the misunderstanding.
|
|
|
|
|