metamorphy
Programmer
I am currently using the following code to make my program pause 10 seconds. It then checks for the existence of a file. If the file is found the program executes a new section of code. Otherwise it keeps on checking. Unfortunately, making my program pause in this way seems to use a lot of system resources. Is there a better way to do this so that other programs that are running are not slowed down.
#include <sys/types.h>
#include <sys/timeb.h>
struct timeb xtime;
struct timeb ytime;
long time1;
long time2;
void wait10()
{
ftime(&xtime);
time1 = xtime.time;
while (!check_time())
{}
//Search for the existence of a file.
}
check_time()
{
ftime(&ytime);
time2= ytime.time;
if (time2 - time1 >= 10)
{return 1;}
else
{return 0;}
}
#include <sys/types.h>
#include <sys/timeb.h>
struct timeb xtime;
struct timeb ytime;
long time1;
long time2;
void wait10()
{
ftime(&xtime);
time1 = xtime.time;
while (!check_time())
{}
//Search for the existence of a file.
}
check_time()
{
ftime(&ytime);
time2= ytime.time;
if (time2 - time1 >= 10)
{return 1;}
else
{return 0;}
}