简体   繁体   中英

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();
}

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM