123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include <QCoreApplication>
- #include "ytservicedog.h"
- YT_SERVICE_SHM *ytShm;
- bool isRuning;
- bool load_shm(){
- int shmid;
- key_t key;
- if((key = ftok(SHM_PATH,static_cast<int>(SHM_PORT)))==-1)
- return false;
- if((shmid = shmget(key,sizeof(YT_SERVICE_SHM),IPC_CREAT|0666))==-1)
- return false;
- ytShm = static_cast<YT_SERVICE_SHM *>(shmat(shmid,nullptr,0));
- return true;
- }
- void chk_program(){
- int ret = 0;
- bool need_start = false;
- time_t uptime = time(static_cast<time_t *>(nullptr));
- if(isRuning)
- return;
- isRuning = true;
- if((uptime-ytShm->updatetime[CORE_MAIN])>300)
- need_start = true;
- // if((uptime-ytShm->updatetime[DB_THREAD])>300)
- // need_start = true;
- if(need_start){
- ytShm->updatetime[CORE_MAIN] = uptime+30;
- ytShm->updatetime[DB_THREAD] = uptime+30;
- ret = system("killall ytServiceCore");
- system("killall ytDP0006");
- system("killall ytDP0007");
- ret = system("ytServiceCore &");
- }
- isRuning = false;
- }
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- isRuning = false;
- if(load_shm()){
- while(1){
- chk_program();
- sleep(1);
- }
- }
- return a.exec();
- }
|