Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Clocking proccesses' time

Reply
Thread Tools

Clocking proccesses' time

 
 
babis85@gmail.com
Guest
Posts: n/a
 
      11-27-2005
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...

 
Reply With Quote
 
 
 
 
Michael Mair
Guest
Posts: n/a
 
      11-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      11-27-2005
On 27 Nov 2005 10:08:50 -0800, (E-Mail Removed) 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/~a...FAQ-acllc.html
 
Reply With Quote
 
babis85@gmail.com
Guest
Posts: n/a
 
      11-27-2005
Ok, then , sorry for that and thanks for the advice.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clocking multiple MFT E1 G703 cards? bob@bfisk.demon.co.uk Cisco 2 12-31-2005 06:18 PM
clocking on a variable Ralf Hildebrandt VHDL 0 06-19-2004 08:17 AM
Re: VWIC-2MFT-T1 card and clocking Henry Yen Cisco 0 04-14-2004 11:01 PM
Cisco MC3810 T1 clocking problem Ed M Cisco 3 11-04-2003 04:46 PM
Boundary scan clocking Yves Tchapda VHDL 0 09-17-2003 04:32 PM



Advertisments