/* * CheckTask.c * * Created on: 2021年9月22日 * Author: 8513 */ #include "CheckSystemTask.h" bool Taskconutstring(char *src, char *taskname) { bool result = false; if (src == NULL || strlen(src) == 0) return result; if (strstr(src, taskname) != NULL && strstr(src, "grep") == NULL && strstr(src, "[") == NULL) { result = true; } return result; } int GetProcessCount(char *procName) { int result = 0; FILE *fp; char cmd[256]; char buf[256]; sprintf(cmd, "ps -ef |grep %s", procName); fp = popen(cmd, "r"); if(fp != NULL) { while(fgets(buf, sizeof(buf), fp) != NULL) { if (Taskconutstring(buf, procName)) result++; } } pclose(fp); return result; } unsigned char CheckSystemTask(unsigned char systemPage) { unsigned char result = 0; unsigned char count_main = GetProcessCount("main"); unsigned char count_evComm = GetProcessCount("Module_EvComm"); unsigned char count_interComm = GetProcessCount("Module_InternalComm"); unsigned char count_eventComm = GetProcessCount("Module_EventLogging"); unsigned char count_primaryComm = GetProcessCount("Module_PrimaryComm"); unsigned char count_lcmComm = GetProcessCount("Module_LcmControl"); unsigned char count_doComm = GetProcessCount("Module_DoComm"); unsigned char count_produceComm = GetProcessCount("Module_ProduceUtils"); // unsigned char count_psuComm = GetProcessCount("Module_PsuComm"); // printf("*************************** \n"); // printf("count_main = %d \n", count_main); // printf("count_eventLog = %d \n", count_eventLog); // printf("count_primary = %d \n", count_primary); // printf("count_evComm = %d \n", count_evComm); // printf("count_lcmCtrl = %d \n", count_lcmCtrl); // printf("count_interComm = %d \n", count_interComm); // printf("count_psuComm = %d \n", count_psuComm); // printf("*************************** \n"); // if (systemPage == 0x09 || systemPage == 0x0A) { if (count_main < _SYSTEM_TASK_COUNT_MAIN ) { system("killall Module_EventLogging"); system("killall Module_PrimaryComm"); system("killall Module_EvComm"); system("killall Module_LcmControl"); system("killall Module_InternalComm"); system("killall Module_DoComm"); // system("killall Module_PsuComm"); // system("killall OcppBackend &"); // system("killall Module_4g &"); // system("killall Module_Wifi &"); system("killall Module_ProduceUtils &"); sleep(3); system("/usr/bin/run_evse_restart.sh"); } else { /* if(system("pidof -s Module_EventLogging > /dev/null") != 0) system("/root/Module_EventLogging &"); if(system("pidof -s Module_PrimaryComm > /dev/null") != 0) system("/root/Module_PrimaryComm &"); if(system("pidof -s Module_LcmControl > /dev/null") != 0) system("/root/Module_LcmControl &"); if(system("pidof -s Module_DoComm > /dev/null") != 0) system("/root/Module_DoComm &"); if(system("pidof -s Module_ProduceUtils > /dev/null") != 0) system("/root/Module_ProduceUtils &"); */ if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM ) { system("killall Module_EvComm"); sleep(3); system("/root/Module_EvComm &"); } if (count_interComm < _SYSTEM_TASK_COUNT_INTERNALCOMM ) { system("killall Module_InternalComm"); sleep(3); system("/root/Module_InternalComm &"); } if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING ) { system("killall Module_EventLogging"); sleep(3); system("/root/Module_EventLogging &"); } if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM ) { system("killall Module_PrimaryComm"); sleep(3); system("/root/Module_PrimaryComm &"); } if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM ) { system("killall Module_LcmControl"); sleep(3); system("/root/Module_LcmControl &"); } if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM ) { system("killall Module_DoComm"); sleep(3); system("/root/Module_DoComm &"); } if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS ) { system("killall Module_ProduceUtils"); sleep(3); system("/root/Module_ProduceUtils &"); } /* if (count_psuComm < 2) { system("killall Module_PsuComm"); sleep(3); system("/root/Module_PsuComm &"); }*/ } sleep(2); } if (count_main < _SYSTEM_TASK_COUNT_MAIN) result = _SYSTEM_TASK_LOST_ITEM_MAIN; else if (count_evComm < _SYSTEM_TASK_COUNT_EVCOMM) result = _SYSTEM_TASK_LOST_ITEM_EVCOMM; /* else if (count_psuComm < 2) result = 3; */ else if (count_eventComm < _SYSTEM_TASK_COUNT_EVENTLOGGING ) result = _SYSTEM_TASK_LOST_ITEM_EVENTLOG; else if (count_primaryComm < _SYSTEM_TASK_COUNT_PRIMARYCOMM) result = _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM; else if (count_lcmComm < _SYSTEM_TASK_COUNT_LCM) result = _SYSTEM_TASK_LOST_ITEM_LCMCONTROL; else if (count_interComm < 2 ) result = _SYSTEM_TASK_LOST_ITEM_INTERCOMM; else if (count_doComm < _SYSTEM_TASK_COUNT_DOCOMM) result = _SYSTEM_TASK_LOST_ITEM_DOCOMM; else if (count_produceComm < _SYSTEM_TASK_COUNT_PRODUCEUTILS) result = _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS; return result; }