Dylan Morison
Dylan Morison

Reputation: 25

Is it posible to relaunch my program after it exits?

Is it posible to relaunch my program after it exits? It's like setting a timer to launch my program, but it does exit each time.

Here is pseudocode:

int main()
{
   MyFunc();  
   exit();
   RestartMeEveryHour();
}

Upvotes: 0

Views: 203

Answers (2)

vit-vit
vit-vit

Reputation: 1376

There may be two different options:

  1. Schedule execution of your program with the operating system. You can do this manually or programmatically through the API. This way may not be portable between different operating systems.
  2. Write an additional program that stays in the background and which will start your first program periodically.

Upvotes: 3

Mats Petersson
Mats Petersson

Reputation: 129314

Besides using cron (in Unix/Linux/OSX) or scheduler (Windows), you can of course do:

int main()
{
    for(;;)
    {
       MyFunc();
       sleepOneHour();
    }
}

Upvotes: 1

Related Questions