can run monitor process 1
This commit is contained in:
parent
664f458da6
commit
2622ccaafc
5
CrossCompile.cmake
Normal file
5
CrossCompile.cmake
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
set(CMAKE_SYSTEM_NAME Linux)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||||
|
|
||||||
|
#cmake -DCMAKE_TOOLCHAIN_FILE=../CrossCompile.cmake ..
|
||||||
|
set(CMAKE_C_COMPILER,"/usr/bin/arm-linux-gnuedbihf-gcc")
|
||||||
2
main.c
2
main.c
@ -24,7 +24,7 @@ int main() {
|
|||||||
while (1) {
|
while (1) {
|
||||||
i++;
|
i++;
|
||||||
printf("\nloop:%d\n", i);
|
printf("\nloop:%d\n", i);
|
||||||
usleep(60000000 / UPDATE_FREQUENCY * 0.98);
|
usleep(600000 / UPDATE_FREQUENCY * 0.98);
|
||||||
//monitor Global_Info and decicde to kill some process
|
//monitor Global_Info and decicde to kill some process
|
||||||
updateSystemInfo();
|
updateSystemInfo();
|
||||||
//monitor Proc_List
|
//monitor Proc_List
|
||||||
|
|||||||
@ -42,6 +42,8 @@ void freeProcInfoList() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//not found,return -1
|
||||||
|
//found,return id
|
||||||
int foundProcNode(unsigned int pid) {
|
int foundProcNode(unsigned int pid) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < LIMIT_PROCESS_NUMBER; i++) {
|
for (i = 0; i < LIMIT_PROCESS_NUMBER; i++) {
|
||||||
@ -77,11 +79,12 @@ int setFreeProcNode(unsigned int pid) {
|
|||||||
printf("/proc/%d/status: %s", pid, buf);
|
printf("/proc/%d/status: %s", pid, buf);
|
||||||
#endif
|
#endif
|
||||||
sscanf(buf, "Name: %s", PID_name);
|
sscanf(buf, "Name: %s", PID_name);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
//compare PID name with whitelist
|
//compare PID name with whitelist
|
||||||
|
|
||||||
//check PID in ProcList
|
//check PID in ProcList
|
||||||
if (foundProcNode(pid) == -1) {
|
if (foundProcNode(pid) != -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +94,25 @@ int setFreeProcNode(unsigned int pid) {
|
|||||||
//set Proc Info
|
//set Proc Info
|
||||||
Proc_List[i].pid = pid;
|
Proc_List[i].pid = pid;
|
||||||
strcpy(Proc_List[i].name, PID_name);
|
strcpy(Proc_List[i].name, PID_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int monitorProcDirChange() {
|
||||||
|
struct dirent **namelist;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = scandir("/proc", &namelist, 0, alphasort);
|
||||||
|
if (n < 0)
|
||||||
|
perror("scandir /proc");
|
||||||
|
else {
|
||||||
|
while (n--) {
|
||||||
|
printf("%s\n", namelist[n]->d_name);
|
||||||
|
free(namelist[n]);
|
||||||
|
}
|
||||||
|
free(namelist);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//unsigned int *getProcess() {
|
//unsigned int *getProcess() {
|
||||||
@ -209,14 +231,14 @@ int updateProcInfo(Proc_Info *proc) {
|
|||||||
void updateProcList() {
|
void updateProcList() {
|
||||||
#if defined(LOG)
|
#if defined(LOG)
|
||||||
printf("/****** Proc Info ******/\n");
|
printf("/****** Proc Info ******/\n");
|
||||||
|
monitorProcDirChange();
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < LIMIT_PROCESS_NUMBER; i++) {
|
for (i = 0; i < LIMIT_PROCESS_NUMBER; i++) {
|
||||||
printf("id=%d,", Proc_List[i].pid);
|
printf("id=%d,", Proc_List[i].pid);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
|
||||||
setFreeProcNode(1);
|
setFreeProcNode(1);
|
||||||
setFreeProcNode(101);
|
#endif
|
||||||
char file_path[64] = {0};
|
char file_path[64] = {0};
|
||||||
int currentProcNode;
|
int currentProcNode;
|
||||||
for (currentProcNode = 0; currentProcNode < LIMIT_PROCESS_NUMBER; currentProcNode++) {
|
for (currentProcNode = 0; currentProcNode < LIMIT_PROCESS_NUMBER; currentProcNode++) {
|
||||||
|
|||||||
@ -30,6 +30,7 @@ typedef struct Proc_Info_ {
|
|||||||
} Proc_Info;
|
} Proc_Info;
|
||||||
|
|
||||||
void freeProcInfo(Proc_Info *proc);
|
void freeProcInfo(Proc_Info *proc);
|
||||||
|
|
||||||
void freeProcInfoList();
|
void freeProcInfoList();
|
||||||
|
|
||||||
//kill this process
|
//kill this process
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user