简体   繁体   English

退出程序后是否可以重新启动程序?

[英]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. 您可以通过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: 除了使用cron (在Unix / Linux / OSX中)或scheduler (Windows)之外,您当然可以:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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