main.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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])>300)
  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+30;
  28. ytShm->updatetime[DB_THREAD] = uptime+30;
  29. ret = system("killall ytServiceCore");
  30. system("killall ytDP0006");
  31. system("killall ytDP0007");
  32. ret = system("ytServiceCore &");
  33. }
  34. isRuning = false;
  35. }
  36. int main(int argc, char *argv[])
  37. {
  38. QCoreApplication a(argc, argv);
  39. isRuning = false;
  40. if(load_shm()){
  41. while(1){
  42. chk_program();
  43. sleep(1);
  44. }
  45. }
  46. return a.exec();
  47. }