can run monitor process 1
This commit is contained in:
+25
-3
@@ -42,6 +42,8 @@ void freeProcInfoList() {
|
||||
return;
|
||||
}
|
||||
|
||||
//not found,return -1
|
||||
//found,return id
|
||||
int foundProcNode(unsigned int pid) {
|
||||
int 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);
|
||||
#endif
|
||||
sscanf(buf, "Name: %s", PID_name);
|
||||
fclose(fp);
|
||||
|
||||
//compare PID name with whitelist
|
||||
|
||||
//check PID in ProcList
|
||||
if (foundProcNode(pid) == -1) {
|
||||
if (foundProcNode(pid) != -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -91,6 +94,25 @@ int setFreeProcNode(unsigned int pid) {
|
||||
//set Proc Info
|
||||
Proc_List[i].pid = pid;
|
||||
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() {
|
||||
@@ -209,14 +231,14 @@ int updateProcInfo(Proc_Info *proc) {
|
||||
void updateProcList() {
|
||||
#if defined(LOG)
|
||||
printf("/****** Proc Info ******/\n");
|
||||
monitorProcDirChange();
|
||||
int i;
|
||||
for (i = 0; i < LIMIT_PROCESS_NUMBER; i++) {
|
||||
printf("id=%d,", Proc_List[i].pid);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
setFreeProcNode(1);
|
||||
setFreeProcNode(101);
|
||||
#endif
|
||||
char file_path[64] = {0};
|
||||
int currentProcNode;
|
||||
for (currentProcNode = 0; currentProcNode < LIMIT_PROCESS_NUMBER; currentProcNode++) {
|
||||
|
||||
@@ -30,6 +30,7 @@ typedef struct Proc_Info_ {
|
||||
} Proc_Info;
|
||||
|
||||
void freeProcInfo(Proc_Info *proc);
|
||||
|
||||
void freeProcInfoList();
|
||||
|
||||
//kill this process
|
||||
|
||||
Reference in New Issue
Block a user