main.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <QCoreApplication>
  2. #include "ytservicedog.h"
  3. YT_SERVICE_SHM *ytShm;
  4. bool isRuning;
  5. bool load_shm(){
  6. int shmid;
  7. key_t key;
  8. if((key = ftok(SHM_PATH,static_cast<int>(SHM_PORT)))==-1)
  9. return false;
  10. if((shmid = shmget(key,sizeof(YT_SERVICE_SHM),IPC_CREAT|0666))==-1)
  11. return false;
  12. ytShm = static_cast<YT_SERVICE_SHM *>(shmat(shmid,nullptr,0));
  13. return true;
  14. }
  15. void chk_program(){
  16. int ret = 0;
  17. bool need_start = false;
  18. time_t uptime = time(static_cast<time_t *>(nullptr));
  19. if(isRuning)
  20. return;
  21. isRuning = true;
  22. if((uptime-ytShm->updatetime[CORE_MAIN])>30)
  23. need_start = true;
  24. // if((uptime-ytShm->updatetime[DB_THREAD])>300)
  25. // need_start = true;
  26. if(need_start){
  27. ytShm->updatetime[CORE_MAIN] = uptime;
  28. ytShm->updatetime[DB_THREAD] = uptime;
  29. ret = system("killall ytServiceCore");
  30. ret = system("/root/bin/ytServiceCore &");
  31. }
  32. isRuning = false;
  33. }
  34. int main(int argc, char *argv[])
  35. {
  36. QCoreApplication a(argc, argv);
  37. isRuning = false;
  38. if(load_shm()){
  39. while(1){
  40. chk_program();
  41. sleep(1);
  42. }
  43. }
  44. return a.exec();
  45. }