-
cpu usage
ok, just to let you all know, this is basically my first complete program, so if what i'm asking is just plain stupid, don't yell.
the program is designed to make a backup of a text file every two hours until manually terminated. the problem i have is that i don't know a good way to make a timer to do that. i tried one way, and yes it runs fine, but it ended up taking about 70% of my cpu resources to run a 90-line program. so obviously that's no good. here's the way i tried to make the timer.
Code:
int main()
{
int x=0;
int diff=0;
long start=0, current=0;
char file_name[15]="";
while(x==0)
{
start=time(NULL);
while(diff<60)
{
current=time(NULL);
diff=current-start;
}
strcat(file_name,get_name());
create_backup(file_name);
}
return 0;
}
if anybody knows a good way to do this(and i'm sure everybody but me does), please let me know. any help is greatly appreciated.
-
Review your compilers documentation to find a sleep() or delay() type function. These local implementations won't hog the CPU like your version.
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
-
ahhh, thanks much. just what i was looking for.