/* * CheckTask.c * * Created on: 2021年9月2日 * Author: 7564 */ #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("Module_CSU"); unsigned char count_evComm = GetProcessCount("Module_EvComm"); unsigned char count_psuComm = GetProcessCount("Module_PsuComm"); if (count_main == 0) count_main = GetProcessCount("main"); // 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 < 5 || count_psuComm < 2) { system("killall Module_EventLogging"); system("killall Module_PrimaryComm"); system("killall Module_EvComm"); system("killall Module_LcmControl"); system("killall Module_InternalComm"); system("killall Module_PsuComm"); system("killall OcppBackend &"); system("killall Module_4g &"); system("killall Module_Wifi &"); system("killall Module_DcMeter &"); 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_InternalComm > /dev/null") != 0) system("/root/Module_InternalComm &"); if (count_evComm < 2) { system("killall Module_EvComm"); sleep(3); system("/root/Module_EvComm &"); } } sleep(2); } if (count_main < 5) result = 1; else if (count_evComm < 2) result = 2; else if (count_psuComm < 2) result = 3; else if (system("pidof -s Module_EventLogging > /dev/null") != 0) result = 4; else if (system("pidof -s Module_PrimaryComm > /dev/null") != 0) result = 5; else if (system("pidof -s Module_LcmControl > /dev/null") != 0) result = 6; else if (system("pidof -s Module_InternalComm > /dev/null") != 0) result = 7; return result; }