|
|
@ -399,24 +399,28 @@ int builtin_history(char **args) |
|
|
|
|
|
|
|
int builtin_mytop() |
|
|
|
{ |
|
|
|
int memory_flag = 0, CPU_flag = 0; |
|
|
|
memory_flag = mytop_memory(); |
|
|
|
CPU_flag = mytop_CPU(); |
|
|
|
if (!memory_flag) |
|
|
|
{ |
|
|
|
return -1; |
|
|
|
} |
|
|
|
else if (!CPU_flag) |
|
|
|
pid_t pid; |
|
|
|
int cputimemode = 1; |
|
|
|
if ((pid = fork()) < 0) |
|
|
|
{ |
|
|
|
return -2; |
|
|
|
printf("fork error\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
else |
|
|
|
if (pid == 0) |
|
|
|
{ |
|
|
|
return 1; |
|
|
|
getkinfo(); |
|
|
|
mytop_memory(); |
|
|
|
get_procs(); |
|
|
|
if (prev_proc == NULL) |
|
|
|
{ |
|
|
|
get_procs(); |
|
|
|
} |
|
|
|
print_procs(prev_proc, proc, cputimemode); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int mytop_memory() |
|
|
|
void mytop_memory() |
|
|
|
{ |
|
|
|
FILE *fp = NULL; |
|
|
|
int pagesize; |
|
|
@ -424,28 +428,15 @@ int mytop_memory() |
|
|
|
|
|
|
|
if ((fp = fopen("/proc/meminfo", "r")) == NULL) |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
|
|
|
|
fscanf(fp, "%u %lu %lu %lu", &pagesize, &total, &free, &cached); |
|
|
|
fclose(fp); |
|
|
|
|
|
|
|
printf("memmory(KBytes):\t%ld total\t%ld free\t%ld cached\n", (pagesize * total) / 1024, (pagesize * free) / 1024, (pagesize * cached) / 1024); |
|
|
|
|
|
|
|
return 1; |
|
|
|
} |
|
|
|
printf("memory(KBytes):\t%ld total\t%ld free\t%ld cached\n", (pagesize * total) / 1024, (pagesize * free) / 1024, (pagesize * cached) / 1024); |
|
|
|
|
|
|
|
int mytop_CPU() |
|
|
|
{ |
|
|
|
int cputimemode = 1; |
|
|
|
getkinfo(); |
|
|
|
get_procs(); |
|
|
|
if (prev_proc == NULL) |
|
|
|
{ |
|
|
|
get_procs(); |
|
|
|
} |
|
|
|
print_procs(prev_proc, proc, cputimemode); |
|
|
|
return 0; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void get_procs() |
|
|
|