ideas on how to make this not use 99% system resources?
Okay this is my code and its pretty simple and self-explainatory. The problem is that this program must be running in the background at all times so I don't want it to use all my CPU power. I know that the reason is because it recreates the time everytime it enters each loop but I can't really think of how else you would constantly update the time. I'm sure it is a very easy concept but I cannot get my mind out of this mode of thinking so insight would be great. Thanks
Code:
#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
int main ( void )
{
time_t now;
struct tm *tm_now;
bool ONTIME;
if (tm_now->tm_hour < 20){
system("ipconfig /release");
ONTIME = false;
cout << "Session ended.\n";
}
else{
ONTIME = true;
}
while(!ONTIME)
{
now = time ( NULL );
tm_now = localtime ( &now );
if (tm_now->tm_hour == 20){
system("ipconfig /renew");
ONTIME = true;
cout << "Session started.\n";
}
}
while(ONTIME)
{
now = time ( NULL );
tm_now = localtime ( &now );
if (tm_now->tm_hour == 0){
system("ipconfig /release");
ONTIME = false;
cout << "Session ended.\n";
}
)
return 0;
}