From bf8b8a79ec448893ae8221873402a844802779ef Mon Sep 17 00:00:00 2001 From: 10195501441 <10195501441@stu.ecnu.edu.com> Date: Thu, 18 Mar 2021 17:15:55 +0800 Subject: [PATCH] test mytop --- yeeshell.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/yeeshell.c b/yeeshell.c index 3e764db..f770542 100644 --- a/yeeshell.c +++ b/yeeshell.c @@ -400,22 +400,17 @@ int builtin_history(char **args) int builtin_mytop() { pid_t pid; - int cputimemode = 1; - if ((pid = fork()) < 0) - { - printf("fork error\n"); - return -1; - } - - getkinfo(); - mytop_memory(); - get_procs(); - if (prev_proc == NULL) + if (pid == 0) { + int cputimemode = 1; + getkinfo(); + mytop_memory(); get_procs(); + if (prev_proc == NULL) + get_procs(); + print_procs(prev_proc, proc, cputimemode); + exit(1); } - print_procs(prev_proc, proc, cputimemode); - exit(0); } void mytop_memory()