From fe2cfb404a3dca1d4d5a2360c66a493fe4786843 Mon Sep 17 00:00:00 2001 From: 10195501441 <10195501441@stu.ecnu.edu.com> Date: Thu, 18 Mar 2021 16:58:56 +0800 Subject: [PATCH] test mytop --- yeeshell.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/yeeshell.c b/yeeshell.c index c39d9be..c243b54 100644 --- a/yeeshell.c +++ b/yeeshell.c @@ -507,15 +507,13 @@ void parse_file(pid_t pid) unsigned long cycles_hi, cycles_lo; FILE *fp; struct proc *p; - int i; int slot; + int i; - sprintf(path, "/proc/%d/psinfo", pid); + sprintf(path, "%d/psinfo", pid); if ((fp = fopen(path, "r")) == NULL) - { return; - } if (fscanf(fp, "%d", &version) != 1) { @@ -535,7 +533,6 @@ void parse_file(pid_t pid) return; } - slot++; slot = SLOT_NR(endpt); if (slot < 0 || slot >= nr_total) @@ -561,6 +558,7 @@ void parse_file(pid_t pid) if (fscanf(fp, " %255s %c %d %d %lu %*u %lu %lu", name, &state, &p->p_blocked, &p->p_priority, &p->p_user_time, &cycles_hi, &cycles_lo) != 7) { + fclose(fp); return; } @@ -580,6 +578,7 @@ void parse_file(pid_t pid) int j; if ((j = fscanf(fp, " %lu %*u %*u %*c %*d %*u %u %*u %d %*c %*d %*u", &p->p_memory, &effuid, &p->p_nice)) != 3) { + fclose(fp); return; }