the init version without error
This commit is contained in:
parent
8c5dd9ca47
commit
c6a798458b
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
3
main.c
3
main.c
@ -9,6 +9,9 @@ int main() {
|
|||||||
pthread_t unix_domain_server;
|
pthread_t unix_domain_server;
|
||||||
|
|
||||||
//init
|
//init
|
||||||
|
//get /data/data/dir
|
||||||
|
//get whitelist
|
||||||
|
//
|
||||||
init();
|
init();
|
||||||
|
|
||||||
//test
|
//test
|
||||||
|
|||||||
@ -62,10 +62,10 @@
|
|||||||
end_data address below which program data+bss is placed
|
end_data address below which program data+bss is placed
|
||||||
start_brk address above which program heap can be expanded with br
|
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 file_path[64] = {0};
|
||||||
char buffer[512] = {0};
|
char buffer[512] = {0};
|
||||||
sprintf(file_path, "/proc/%d/stat", &proc->pid);
|
sprintf(file_path, "/proc/%ls/stat", &proc->pid);
|
||||||
|
|
||||||
FILE *fd = NULL;
|
FILE *fd = NULL;
|
||||||
fd = fopen(file_path, "r");
|
fd = fopen(file_path, "r");
|
||||||
@ -94,23 +94,19 @@ inline int updateProcInfo(struct Proc_Info *proc) {
|
|||||||
int pass;
|
int pass;
|
||||||
}
|
}
|
||||||
if (count == STAT_RSS) { //counted by page(4K)
|
if (count == STAT_RSS) { //counted by page(4K)
|
||||||
|
proc->memInfo->rss *= 4;
|
||||||
int pass;
|
int pass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p++;
|
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);
|
fclose(fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateProcList() {
|
void updateProcList() {
|
||||||
struct Proc_Info *proc;
|
Proc_Info *proc;
|
||||||
char file_path[64] = {0};
|
char file_path[64] = {0};
|
||||||
while (1) {
|
while (1) {
|
||||||
if (Proc_List_ID == 30) {
|
if (Proc_List_ID == 30) {
|
||||||
@ -122,7 +118,7 @@ void updateProcList() {
|
|||||||
if (&proc->pid != 0) {
|
if (&proc->pid != 0) {
|
||||||
if (updateProcInfo(proc) == -1) {
|
if (updateProcInfo(proc) == -1) {
|
||||||
//check path exist
|
//check path exist
|
||||||
sprintf(file_path, "/proc/%d", &proc->pid);
|
sprintf(file_path, "/proc/%ls", &proc->pid);
|
||||||
if (access(file_path, F_OK)) {
|
if (access(file_path, F_OK)) {
|
||||||
proc->pid = 0;
|
proc->pid = 0;
|
||||||
}
|
}
|
||||||
@ -130,4 +126,5 @@ void updateProcList() {
|
|||||||
}
|
}
|
||||||
Proc_List_ID++;
|
Proc_List_ID++;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
@ -6,28 +6,28 @@
|
|||||||
#define ATOP_MONITORPROCESS_H
|
#define ATOP_MONITORPROCESS_H
|
||||||
|
|
||||||
//proc/PID/stat
|
//proc/PID/stat
|
||||||
typedef struct Proc_CPU_Time {
|
typedef struct {
|
||||||
unsigned long utime; //user time
|
unsigned long utime; //user time
|
||||||
unsigned long stime; //kernel time
|
unsigned long stime; //kernel time
|
||||||
};
|
} Proc_CPU_Time;
|
||||||
|
|
||||||
//proc/PID/statm,the value should multiply 4
|
//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 vsz; //Virtual Memory Size, includes all memory that the process can access
|
||||||
unsigned long rss; //Resident Set Size
|
unsigned long rss; //Resident Set Size
|
||||||
};
|
} Proc_Mem;
|
||||||
|
|
||||||
typedef struct Proc_Info {
|
typedef struct Proc_Info_ {
|
||||||
unsigned int pid;
|
unsigned int pid;
|
||||||
char name[128];
|
char name[128];
|
||||||
int point; //0-29
|
int point; //0-29
|
||||||
struct Proc_CPU_Time cpuInfo[30];
|
Proc_CPU_Time cpuInfo[30];
|
||||||
struct Proc_Mem memInfo[30];
|
Proc_Mem memInfo[30];
|
||||||
};
|
} Proc_Info;
|
||||||
|
|
||||||
int Proc_List_Free_ID = 0;
|
int Proc_List_Free_ID = 0;
|
||||||
int Proc_List_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
|
//kill this process
|
||||||
void findProcListByMem();
|
void findProcListByMem();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user