473,796 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clocking proccesses' time

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(RUSAG E_CHILDREN, &ru1);
waitpid(-1, &status, 0);
getrusage(_CHIL DREN, &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(RUSAG E_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 '05 #1
3 1971
ba*****@gmail.c om 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.progr ammer or similar may be a better place to ask.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 27 '05 #2
On 27 Nov 2005 10:08:50 -0800, ba*****@gmail.c om 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(RUSAG E_CHILDREN, &ru1);
waitpid(-1, &status, 0);
getrusage(_CHIL DREN, &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(RUSAG E_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.li nux.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.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 27 '05 #3
Ok, then , sorry for that and thanks for the advice.

Nov 27 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11725
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 set my cookie with: setcookie('CookieName', $SomeValue, time()+3600, "/");
2
2889
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 updating if you hit the key (refresh) it inserts another record ... I have tried: 1. Clearing the vMemo field after the insert is done (vMemo = "") 2. Setting the value on the form for this field to "" Neither of these are working. It's not...
6
2856
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 across the country. txtRaceTime will always be set to Central Time regardless of where we are in the US. At first I tried ‘Now() – “xx:xx:xx” but that produced an error. Anyway as we approach the east coast the ‘minus’ would need to be a...
2
5513
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 something). I have already learned how to do a "progress bar" type solution, which lets me calculate percentages. This is different however, because rate implies time. I've tried making a timer that goes off once a second and then applying (bytes...
4
1121
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 ....
0
816
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 SELECT query and get the results after i dispose the WS, a proccess of the WS is still active on the Proccesses of the SQL, as you can imaging after 10 minutes of asking the WS (every 30sec) and dispose it each time the proccesses in the SQL are...
5
2106
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 scanner and not need to touch the mouse or keyboard. i can successfully clock in but i am havin difficulties when it comes to clocking out i am no good with VBA code but if anyone could help me with if true statements or other ways to produce...
1
1458
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 and the second one contains the field for the time they are leaving (timeout) My problem is that I don’t know how to connect these two tables in the query to show the results and make the calculations need for the total working time for every...
3
6248
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 numerical simulations under Ubuntu, and using Python as my scripting language to automatically manage input and output. I need to have a precise performance measurement (CPU time) of how long it takes to run my simulations.
0
9530
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.