diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/main.c b/main.c index a98cb94..edb3100 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,9 @@ int main() { pthread_t unix_domain_server; //init + //get /data/data/dir + //get whitelist + // init(); //test diff --git a/src/MonitorProcess.c b/src/MonitorProcess.c index dca21d6..2d044cf 100644 --- a/src/MonitorProcess.c +++ b/src/MonitorProcess.c @@ -62,10 +62,10 @@ end_data address below which program data+bss is placed start_brk address above which program heap can be expanded with br */ -inline int updateProcInfo(struct Proc_Info *proc) { +int updateProcInfo(Proc_Info *proc) { char file_path[64] = {0}; char buffer[512] = {0}; - sprintf(file_path, "/proc/%d/stat", &proc->pid); + sprintf(file_path, "/proc/%ls/stat", &proc->pid); FILE *fd = NULL; fd = fopen(file_path, "r"); @@ -94,23 +94,19 @@ inline int updateProcInfo(struct Proc_Info *proc) { int pass; } if (count == STAT_RSS) { //counted by page(4K) + proc->memInfo->rss *= 4; int pass; } } p++; } - - fgets(line_buff, sizeof(line_buff), fd); - sscanf(line_buff, "%ld %ld ", &proc->memInfo->vsz, &proc->memInfo->rss); - proc->memInfo->vsz *= 4; - proc->memInfo->rss *= 4; fclose(fd); return 0; } void updateProcList() { - struct Proc_Info *proc; + Proc_Info *proc; char file_path[64] = {0}; while (1) { if (Proc_List_ID == 30) { @@ -122,7 +118,7 @@ void updateProcList() { if (&proc->pid != 0) { if (updateProcInfo(proc) == -1) { //check path exist - sprintf(file_path, "/proc/%d", &proc->pid); + sprintf(file_path, "/proc/%ls", &proc->pid); if (access(file_path, F_OK)) { proc->pid = 0; } @@ -130,4 +126,5 @@ void updateProcList() { } Proc_List_ID++; } + return; } \ No newline at end of file diff --git a/src/MonitorProcess.h b/src/MonitorProcess.h index 5556f89..2751d32 100644 --- a/src/MonitorProcess.h +++ b/src/MonitorProcess.h @@ -6,28 +6,28 @@ #define ATOP_MONITORPROCESS_H //proc/PID/stat -typedef struct Proc_CPU_Time { +typedef struct { unsigned long utime; //user time unsigned long stime; //kernel time -}; +} Proc_CPU_Time; //proc/PID/statm,the value should multiply 4 -typedef struct Proc_Mem { +typedef struct Proc_Mem_ { unsigned long vsz; //Virtual Memory Size, includes all memory that the process can access unsigned long rss; //Resident Set Size -}; +} Proc_Mem; -typedef struct Proc_Info { +typedef struct Proc_Info_ { unsigned int pid; char name[128]; int point; //0-29 - struct Proc_CPU_Time cpuInfo[30]; - struct Proc_Mem memInfo[30]; -}; + Proc_CPU_Time cpuInfo[30]; + Proc_Mem memInfo[30]; +} Proc_Info; int Proc_List_Free_ID = 0; int Proc_List_ID = 0; -struct Proc_Info Proc_List[64]; //max monitor 64 process +Proc_Info Proc_List[64]; //max monitor 64 process //kill this process void findProcListByMem();