-
September 13th, 2005, 10:26 PM
#1
not know
Hi!
I traing to develop my first tool for monitiring of some changes in windows but I got big problem and do not know where to look.
I can nothing about classes and struct, difficult to understand yet. And I using just simple functions for that. "Ehhh, may be it is problem"
I used time function for that, to pause time,
[gloworange]
seconds = time ( NULL ) ;
int i = seconds;
while ( i > seconds ) seconds = time ( NULL ) ;
[/gloworange]
but i getting up to 100% process usage. Do you know what to do or where I can get answer for that? PM me then.
// too far away outside of limit
-
September 13th, 2005, 11:16 PM
#2
Re: not know
Originally posted here by MrBabis
Hi!
I traing to develop my first tool for monitiring of some changes in windows but I got big problem and do not know where to look.
I can nothing about classes and struct, difficult to understand yet. And I using just simple functions for that. "Ehhh, may be it is problem"
I used time function for that, to pause time,
[gloworange]
seconds = time ( NULL ) ;
int i = seconds;
while ( i > seconds ) seconds = time ( NULL ) ;
[/gloworange]
but i getting up to 100% process usage. Do you know what to do or where I can get answer for that? PM me then.
Ummm.. that code won't do anything useful I wouldn't think... Let me run through it...
you have seconds = time (NULL);
From that you're setting a variable called seconds to be whatever time(NULL) returns... just for simplicity, we'll pick the number 5.
Then you have int i = seconds;
This should set i to equal seconds... so now i=5 and seconds=5.
Then you have while (i > seconds) seconds = time(NULL);
Well, i is never greater than seconds because you just set them equal to each other.
I'm not really sure what you're looking for, but I have a feeling that this snippet of code isn't setting your CPU to 100%.
-
September 13th, 2005, 11:23 PM
#3
oops
"i" can be modifed simple by adding some more. And when I do that I getting 100% at CPU.
I using Borland C++ Trial. If it do somthing.
// too far away outside of limit
-
September 13th, 2005, 11:40 PM
#4
I would suggest something simple, like... output what i and seconds are during each loop. Or even comment out the loop and just output what i and seconds are before the loop and start there. I have a strange feeling that time(NULL) is returning 0.
-
September 14th, 2005, 12:59 AM
#5
whole code:
#include <time.h>
#include <iostream.h>
int TESTER (void)
{
time_t seconds;
seconds = time (NULL);
int i=(seconds+10);
while(i>seconds) seconds = time (NULL);
return seconds;
}
exempel taken from:
http://www.cplusplus.com/ref/ctime/time.html
// too far away outside of limit
-
September 14th, 2005, 03:26 AM
#6
Ok, a couple things that I noticed.. First, shouldn't this be a main function? Secondly, you're doing an improper type comparison of time_t and int. They might be equivilent but I would suggest making them the same type. I assume that there is a method for the > operator of time_t type. I ran this code on my machine and it worked fine. 10 seconds of computing and then it quits. Try this code and tell me what you get.
#include <time.h>
#include <iostream.h>
int main()
{
time_t seconds;
time(&seconds);
time_t i = seconds+10;
while(i > seconds) {
time(&seconds);
printf ("Seconds: %ld \n", seconds);
printf ("I: %ld \n", i);
}
return 0;
}
-
September 14th, 2005, 09:25 AM
#7
I still getting high cpu usage.
// too far away outside of limit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|