the init version without error

This commit is contained in:
Iain 2021-07-19 20:34:45 +08:00
parent 8c5dd9ca47
commit c6a798458b
4 changed files with 18 additions and 18 deletions

0
.gitignore vendored Normal file
View File

3
main.c
View File

@ -9,6 +9,9 @@ int main() {
pthread_t unix_domain_server;
//init
//get /data/data/dir
//get whitelist
//
init();
//test

View File

@ -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;
}

View File

@ -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();