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... 3 1949 ba*****@gmail.com 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.
On 27 Nov 2005 10:08:50 -0800, ba*****@gmail.com 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
Ok, then , sorry for that and thanks for the advice. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dan glenn |
last post by:
Say,
I want to set a cookie and have it expire an hour after it's set. It's
looking like this is only possible for browsers which are in the same time
zone as my server??
In other words, if I...
|
by: Robin |
last post by:
Ok, I have a form that on clicking of the Update button first updates
the specific record in the db, then Inserts if the vMemo field is not
empty. The problem that I'm having is that After...
|
by: Rebecca Smith |
last post by:
Today’s question involves two time text boxes each set to a different time
zone. Initially txtCurrentTime will be set to Pacific Time or system time.
This will change with system time as we travel...
|
by: None |
last post by:
I'm using the HttpWebRequest/Response methods and I'm trying to figure
out how to calculate the effective transfer rare the file is being
received at (like you see in IE when you download...
|
by: Rich |
last post by:
Hello,
I am trying to measure the elapsed time between 2
processes. If I declare startTime As Double, endTime as
Double and say
startTime = Timer
....
process1
....
|
by: Nassos |
last post by:
Hello all,
We made a program that syncronize 2 db over the net, for that we build a
WebService that sits at the server that one of the dbs is sitting (SQL), now
every time that the WS is running a...
|
by: madgunnercurz |
last post by:
i currently have a database for tracking members arrival and exit
times. however due to new demands my training centre are wanting a
barcode system setup where all the user has to do is use a wedge...
|
by: anchamal |
last post by:
I’m using Ms Access 2003 and I have this problem in the query,
I created two tables named timein and timeout. The first one contains the time field that the employees are coming (timein) to work...
|
by: barnburnr |
last post by:
Hi,
I've seen several threads on this subject, but haven't (yet) run
across one that answers my specific questions. This should be really
easy for someone, so here goes:
I'm running some...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |