-
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.
-
Re: not know
Quote:
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%.
-
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.
-
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.
-
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
-
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;
}
-
I still getting high cpu usage.