From b0ad49bf14fb60dc1d046eadc9d832c0c8ed306d Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:13:16 -0700 Subject: [PATCH 01/34] added document file --- docs/ps.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 docs/ps.txt diff --git a/docs/ps.txt b/docs/ps.txt new file mode 100644 index 0000000..1c6d0fc --- /dev/null +++ b/docs/ps.txt @@ -0,0 +1,25 @@ +**ps** displays information about active processes. The initial version will display all processes: pid, parent pid, current state, memory size, and program name. Processes in UNUSED state will be ignored. The initial version will support a -h flag for program information. + +**Approach**: Update kernel as needed to introduce 22nd system call: getprocs and sys_getprocs. ps will pass a struct (ptable data) array pointer to the system call (getprocs). getprocs will iterate through all ptable entries where state != UNUSED and update the passed struct array pointer with ptable data via copyout. ps will output the returned ptable data in a nicely formatted manner. If the -h argument is used, ps will output simple help information and exit. + +**Files modified/added:* + +kernel: + +- syscall.c (sys_getprocs function declaration, update syscalls) +- syscall.h (define SYS_getprocs 22) +- sysproc.c (function sys_getprocs) +- usys.S (add SYSCALL(getprocs)) +- proc.c (code for getprocs) +- refs.h (function declaration) + +user: + +- user.h (add system call) +- ps.c (new: call getprocs and output returned ptable data) +- usys.pl + +Future Development + +- Add support for outputting command line (argv[0]) and arguments (argv[1..n]) instead of process name. +- Add support for -t flag to output process information by parent/child in tree format From 6552aff0da6d09159cf326f4b16c7d026350033f Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:16:34 -0700 Subject: [PATCH 02/34] added sys_getprocs --- kernel/syscall.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/kernel/syscall.c b/kernel/syscall.c index ed65409..f6ea699 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -101,31 +101,33 @@ extern uint64 sys_unlink(void); extern uint64 sys_link(void); extern uint64 sys_mkdir(void); extern uint64 sys_close(void); +extern uint64 sys_getprocs(void); // An array mapping syscall numbers from syscall.h // to the function that handles the system call. static uint64 (*syscalls[])(void) = { -[SYS_fork] sys_fork, -[SYS_exit] sys_exit, -[SYS_wait] sys_wait, -[SYS_pipe] sys_pipe, -[SYS_read] sys_read, -[SYS_kill] sys_kill, -[SYS_exec] sys_exec, -[SYS_fstat] sys_fstat, -[SYS_chdir] sys_chdir, -[SYS_dup] sys_dup, -[SYS_getpid] sys_getpid, -[SYS_sbrk] sys_sbrk, -[SYS_sleep] sys_sleep, -[SYS_uptime] sys_uptime, -[SYS_open] sys_open, -[SYS_write] sys_write, -[SYS_mknod] sys_mknod, -[SYS_unlink] sys_unlink, -[SYS_link] sys_link, -[SYS_mkdir] sys_mkdir, -[SYS_close] sys_close, +[SYS_fork] sys_fork, +[SYS_exit] sys_exit, +[SYS_wait] sys_wait, +[SYS_pipe] sys_pipe, +[SYS_read] sys_read, +[SYS_kill] sys_kill, +[SYS_exec] sys_exec, +[SYS_fstat] sys_fstat, +[SYS_chdir] sys_chdir, +[SYS_dup] sys_dup, +[SYS_getpid] sys_getpid, +[SYS_sbrk] sys_sbrk, +[SYS_sleep] sys_sleep, +[SYS_uptime] sys_uptime, +[SYS_open] sys_open, +[SYS_write] sys_write, +[SYS_mknod] sys_mknod, +[SYS_unlink] sys_unlink, +[SYS_link] sys_link, +[SYS_mkdir] sys_mkdir, +[SYS_close] sys_close, +[SYS_getprocs] sys_getprocs }; void From 03483c401277afa5e35c65b5bcbdbdec151efdc3 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:18:05 -0700 Subject: [PATCH 03/34] added define for SYS_getprocs 22 --- kernel/syscall.h | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/kernel/syscall.h b/kernel/syscall.h index bc5f356..15bf85c 100644 --- a/kernel/syscall.h +++ b/kernel/syscall.h @@ -1,22 +1,23 @@ // System call numbers -#define SYS_fork 1 -#define SYS_exit 2 -#define SYS_wait 3 -#define SYS_pipe 4 -#define SYS_read 5 -#define SYS_kill 6 -#define SYS_exec 7 -#define SYS_fstat 8 -#define SYS_chdir 9 -#define SYS_dup 10 -#define SYS_getpid 11 -#define SYS_sbrk 12 -#define SYS_sleep 13 -#define SYS_uptime 14 -#define SYS_open 15 -#define SYS_write 16 -#define SYS_mknod 17 -#define SYS_unlink 18 -#define SYS_link 19 -#define SYS_mkdir 20 -#define SYS_close 21 +#define SYS_fork 1 +#define SYS_exit 2 +#define SYS_wait 3 +#define SYS_pipe 4 +#define SYS_read 5 +#define SYS_kill 6 +#define SYS_exec 7 +#define SYS_fstat 8 +#define SYS_chdir 9 +#define SYS_dup 10 +#define SYS_getpid 11 +#define SYS_sbrk 12 +#define SYS_sleep 13 +#define SYS_uptime 14 +#define SYS_open 15 +#define SYS_write 16 +#define SYS_mknod 17 +#define SYS_unlink 18 +#define SYS_link 19 +#define SYS_mkdir 20 +#define SYS_close 21 +#define SYS_getprocs 22 From 0c7d708568a83bc87750a8217f999f2c7ee65198 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:19:59 -0700 Subject: [PATCH 04/34] added stub for sys_getprocs --- kernel/sysproc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 1de184e..2191b84 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -89,3 +89,9 @@ sys_uptime(void) release(&tickslock); return xticks; } + +uint64 +sys_getprocs(void) { + //TODO I think this call needs to validate args passed to getprocs + return 0; +} From a97c84e36690252807de95e260269a644abdc74f Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:21:13 -0700 Subject: [PATCH 05/34] added getprocs --- user/usys.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/user/usys.pl b/user/usys.pl index 01e426e..54ce97f 100755 --- a/user/usys.pl +++ b/user/usys.pl @@ -36,3 +36,4 @@ sub entry { entry("sbrk"); entry("sleep"); entry("uptime"); +entry("getprocs"); From 1b4b372f754bb1defa08928efad7085bfa23dc2c Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:23:52 -0700 Subject: [PATCH 06/34] corrected files modified --- docs/ps.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ps.txt b/docs/ps.txt index 1c6d0fc..7ca826e 100644 --- a/docs/ps.txt +++ b/docs/ps.txt @@ -9,9 +9,9 @@ kernel: - syscall.c (sys_getprocs function declaration, update syscalls) - syscall.h (define SYS_getprocs 22) - sysproc.c (function sys_getprocs) -- usys.S (add SYSCALL(getprocs)) - proc.c (code for getprocs) - refs.h (function declaration) +- usys.pl (add entry) user: From 5ae567933aff09fb75d2034778d3098e80d0b143 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:30:53 -0700 Subject: [PATCH 07/34] added entry got getprocs(void) dont know how to pass args yet --- kernel/defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/defs.h b/kernel/defs.h index a3c962b..fbcb72b 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -106,6 +106,7 @@ void yield(void); int either_copyout(int user_dst, uint64 dst, void *src, uint64 len); int either_copyin(void *dst, int user_src, uint64 src, uint64 len); void procdump(void); +int getprocs(void); // swtch.S void swtch(struct context*, struct context*); From a44c1f72e0100479c9c40201c6a114a0471a525e Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:31:56 -0700 Subject: [PATCH 08/34] added getprocs stub-- no args yet --- user/user.h | 1 + 1 file changed, 1 insertion(+) diff --git a/user/user.h b/user/user.h index 2e6fc55..4da6769 100644 --- a/user/user.h +++ b/user/user.h @@ -22,6 +22,7 @@ int getpid(void); char* sbrk(int); int sleep(int); int uptime(void); +int getprocs(void); // ulib.c int stat(const char*, struct stat*); From bcb538924f5839db2ab8b635151de20b85c147b1 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:34:29 -0700 Subject: [PATCH 09/34] added stub getprocs to count entries in ptable --- kernel/proc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kernel/proc.c b/kernel/proc.c index 031eeb5..0ba1479 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -688,3 +688,17 @@ procdump(void) printf("\n"); } } + +int +getNumProc(void) +{ + struct proc *p; + int count = 0; + + for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { + if(p->state != UNUSED) + count++; + } + + return count; +} From 5d2a0905fdbf78459338252971e7e566a8322603 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:35:47 -0700 Subject: [PATCH 10/34] copied proddump loop for testing --- kernel/proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/proc.c b/kernel/proc.c index 0ba1479..cf195c0 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -695,7 +695,7 @@ getNumProc(void) struct proc *p; int count = 0; - for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { + for(p = proc; p < proc[NPROC]; p++) { if(p->state != UNUSED) count++; } From ebe76f3ab9806e2e49bc53a43b787cfcaf3e966a Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:37:50 -0700 Subject: [PATCH 11/34] fixed bug in for loop --- kernel/proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/proc.c b/kernel/proc.c index cf195c0..79ca81d 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -695,7 +695,7 @@ getNumProc(void) struct proc *p; int count = 0; - for(p = proc; p < proc[NPROC]; p++) { + for(p = proc; p < &proc[NPROC]; p++) { if(p->state != UNUSED) count++; } From 067bc8c8b16002aa20263fc9e7dcc33e69fc65c7 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:44:52 -0700 Subject: [PATCH 12/34] first stab at ps that outputs num running proccesses doesnt work yet --- Makefile | 1 + kernel/proc.c | 2 +- user/ps.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 user/ps.c diff --git a/Makefile b/Makefile index 2584e4a..a8de518 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,7 @@ UPROGS=\ $U/_ln\ $U/_ls\ $U/_mkdir\ + $U/_ps\ $U/_rm\ $U/_sh\ $U/_stressfs\ diff --git a/kernel/proc.c b/kernel/proc.c index 79ca81d..a74d8d1 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -690,7 +690,7 @@ procdump(void) } int -getNumProc(void) +getprocs(void) { struct proc *p; int count = 0; diff --git a/user/ps.c b/user/ps.c new file mode 100644 index 0000000..053b88a --- /dev/null +++ b/user/ps.c @@ -0,0 +1,10 @@ +#include "kernel/types.h" +#include "kernel/stat.h" +#include "kernel/fcntl.h" +#include "user/user.h" + +int main (int argc, int **argv) { + int tot = getprocs(); + printf("%d processes are running\n", tot); + exit(0); +} From 2093ad3e0158dfa13e658052c0ac5b065e88ca6a Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 07:47:59 -0700 Subject: [PATCH 13/34] connected sys_getprocs to getprocs and it works! --- kernel/sysproc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 2191b84..358e149 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -93,5 +93,6 @@ sys_uptime(void) uint64 sys_getprocs(void) { //TODO I think this call needs to validate args passed to getprocs - return 0; + //return 1; + return getprocs(); } From 03f38b2694da363499e4b1c390ecf73978de760b Mon Sep 17 00:00:00 2001 From: geoweb999 Date: Sun, 8 Sep 2024 07:54:00 -0700 Subject: [PATCH 14/34] Update ps.txt with status --- docs/ps.txt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/ps.txt b/docs/ps.txt index 7ca826e..4fab4e1 100644 --- a/docs/ps.txt +++ b/docs/ps.txt @@ -6,18 +6,17 @@ kernel: -- syscall.c (sys_getprocs function declaration, update syscalls) -- syscall.h (define SYS_getprocs 22) -- sysproc.c (function sys_getprocs) -- proc.c (code for getprocs) -- refs.h (function declaration) -- usys.pl (add entry) +- syscall.c (sys_getprocs function declaration, update syscalls) ✅ +- syscall.h (define SYS_getprocs 22) ✅ +- sysproc.c (function sys_getprocs) ✅ +- proc.c (code for getprocs) ✅ +- defs.h (function declaration)??? ✅ user: -- user.h (add system call) -- ps.c (new: call getprocs and output returned ptable data) -- usys.pl +- user.h (add system call) ✅ +- ps.c (new: call getprocs and output returned ptable data) ✅ +- usys.pl ✅ Future Development From c17ff3d6d0fd62fa76cf09721c3b7730dc5e114f Mon Sep 17 00:00:00 2001 From: geoweb999 Date: Sun, 8 Sep 2024 07:54:48 -0700 Subject: [PATCH 15/34] Update ps.txt --- docs/ps.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ps.txt b/docs/ps.txt index 4fab4e1..7f97492 100644 --- a/docs/ps.txt +++ b/docs/ps.txt @@ -15,7 +15,7 @@ kernel: user: - user.h (add system call) ✅ -- ps.c (new: call getprocs and output returned ptable data) ✅ +- ps.c (new: call getprocs and output returned ptable data) ✅ (only returns number of non-UNUSED entries in proc table for now) - usys.pl ✅ Future Development From 17327a5fd634ed32215b83421fb353497f02f3f0 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 09:48:02 -0700 Subject: [PATCH 16/34] figured out how to pass args to syscall via argaddr/argint --- kernel/defs.h | 3 ++- kernel/proc.c | 2 +- kernel/proc.h | 9 +++++++++ kernel/sysproc.c | 10 ++++++++-- user/ps.c | 19 ++++++++++++++++++- user/user.h | 3 ++- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/kernel/defs.h b/kernel/defs.h index fbcb72b..8a881a3 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -8,6 +8,7 @@ struct spinlock; struct sleeplock; struct stat; struct superblock; +struct proc_data; // bio.c void binit(void); @@ -106,7 +107,7 @@ void yield(void); int either_copyout(int user_dst, uint64 dst, void *src, uint64 len); int either_copyin(void *dst, int user_src, uint64 src, uint64 len); void procdump(void); -int getprocs(void); +int getprocs(struct proc_data*, int max); // swtch.S void swtch(struct context*, struct context*); diff --git a/kernel/proc.c b/kernel/proc.c index a74d8d1..d5a7537 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -690,7 +690,7 @@ procdump(void) } int -getprocs(void) +getprocs(struct proc_data *pd, int max) { struct proc *p; int count = 0; diff --git a/kernel/proc.h b/kernel/proc.h index d021857..871446f 100644 --- a/kernel/proc.h +++ b/kernel/proc.h @@ -105,3 +105,12 @@ struct proc { struct inode *cwd; // Current directory char name[16]; // Process name (debugging) }; + +// procstate data used by getprocs +struct proc_data { + int pid; + int ppid; + int state; + uint sz; + char name[16]; +}; diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 358e149..b155b13 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -93,6 +93,12 @@ sys_uptime(void) uint64 sys_getprocs(void) { //TODO I think this call needs to validate args passed to getprocs - //return 1; - return getprocs(); + struct proc_data *pd; + int max; + + //argaddr(int n, uint64 *ip) + + argaddr(0, (uint64 *)&pd); + argint(1, &max); + return getprocs(pd, max); } diff --git a/user/ps.c b/user/ps.c index 053b88a..7826a8f 100644 --- a/user/ps.c +++ b/user/ps.c @@ -3,8 +3,25 @@ #include "kernel/fcntl.h" #include "user/user.h" +#define MAX_PROCS 64 + +struct proc_data { + int pid; + int ppid; + int state; + int sz; + char name[16]; +}; + int main (int argc, int **argv) { - int tot = getprocs(); + struct proc_data pd[MAX_PROCS]; + + int tot = getprocs(pd, MAX_PROCS); + if (tot < 0) { + printf("getprocs failed\n"); + exit(1); + } + printf("%d processes are running\n", tot); exit(0); } diff --git a/user/user.h b/user/user.h index 4da6769..79b9823 100644 --- a/user/user.h +++ b/user/user.h @@ -1,4 +1,5 @@ struct stat; +struct proc_data; // system calls int fork(void); @@ -22,7 +23,7 @@ int getpid(void); char* sbrk(int); int sleep(int); int uptime(void); -int getprocs(void); +int getprocs(struct proc_data *, int); // ulib.c int stat(const char*, struct stat*); From 5435f75c2994d7db35f0dcae92221f54c55c8c4a Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 12:22:51 -0700 Subject: [PATCH 17/34] have kernel side proc_info set up. need to figure out copyout now --- kernel/proc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/proc.c b/kernel/proc.c index d5a7537..f72703d 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -693,11 +693,22 @@ int getprocs(struct proc_data *pd, int max) { struct proc *p; + struct proc_data kpd[64]; int count = 0; for(p = proc; p < &proc[NPROC]; p++) { - if(p->state != UNUSED) - count++; + if (p->state == UNUSED) { + continue; + } + if (count > max) { + break; + } + kpd[count].pid = p->pid; + kpd[count].ppid = p->parent ? p->parent->pid : 0; + kpd[count].state = p->state; + kpd[count].sz = p->sz; + safestrcpy(kpd[count].name, p->name, sizeof(kpd[count].name)); + count++; } return count; From c0707e004c7a56bd5a1921101dda9e5300f57152 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 12:30:51 -0700 Subject: [PATCH 18/34] copyout compiles and doesnt cause kernel panic --- kernel/proc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/proc.c b/kernel/proc.c index f72703d..167b35e 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -710,6 +710,7 @@ getprocs(struct proc_data *pd, int max) safestrcpy(kpd[count].name, p->name, sizeof(kpd[count].name)); count++; } + copyout(p->pagetable, (uint64)&pd, (char *)kpd, count * sizeof(struct proc_data)); return count; } From bd69dcf78d87f6cae048fb53a09fdd0b0b0659f3 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 12:35:13 -0700 Subject: [PATCH 19/34] updated to print out process info but data all zero :( --- user/ps.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/user/ps.c b/user/ps.c index 7826a8f..e6f3a7b 100644 --- a/user/ps.c +++ b/user/ps.c @@ -23,5 +23,11 @@ int main (int argc, int **argv) { } printf("%d processes are running\n", tot); + printf("PID\tPPID\tSTATE\tSIZE\tNAME\n"); + + int i; + for (i = 0; i < tot; i++) { + printf("%d\t%d\t%d\t%d\t%s\n",pd[i].pid, pd[i].ppid, pd[i].state,pd[i].sz, pd[i].name); + } exit(0); } From cfb8cae0c6352d6ea9c08e7750d8f0359299912f Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 13:59:34 -0700 Subject: [PATCH 20/34] debugging-- switched param1 of getprocs to proc_info**, still not working --- kernel/defs.h | 2 +- kernel/proc.c | 7 ++++--- kernel/sysproc.c | 2 +- user/ps.c | 5 ++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/defs.h b/kernel/defs.h index 8a881a3..7f630e1 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -107,7 +107,7 @@ void yield(void); int either_copyout(int user_dst, uint64 dst, void *src, uint64 len); int either_copyin(void *dst, int user_src, uint64 src, uint64 len); void procdump(void); -int getprocs(struct proc_data*, int max); +int getprocs(struct proc_data**, int max); // swtch.S void swtch(struct context*, struct context*); diff --git a/kernel/proc.c b/kernel/proc.c index 167b35e..9623579 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -690,10 +690,10 @@ procdump(void) } int -getprocs(struct proc_data *pd, int max) +getprocs(struct proc_data **pd, int max) { struct proc *p; - struct proc_data kpd[64]; + struct proc_data kpd[NPROC]; int count = 0; for(p = proc; p < &proc[NPROC]; p++) { @@ -708,9 +708,10 @@ getprocs(struct proc_data *pd, int max) kpd[count].state = p->state; kpd[count].sz = p->sz; safestrcpy(kpd[count].name, p->name, sizeof(kpd[count].name)); + printf("%s\n", kpd[count].name); count++; } - copyout(p->pagetable, (uint64)&pd, (char *)kpd, count * sizeof(struct proc_data)); + copyout(p->pagetable, (uint64)&pd, (char *)kpd, max * sizeof(struct proc_data)); return count; } diff --git a/kernel/sysproc.c b/kernel/sysproc.c index b155b13..2838e2d 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -100,5 +100,5 @@ sys_getprocs(void) { argaddr(0, (uint64 *)&pd); argint(1, &max); - return getprocs(pd, max); + return getprocs(&pd, max); } diff --git a/user/ps.c b/user/ps.c index e6f3a7b..9b7cefb 100644 --- a/user/ps.c +++ b/user/ps.c @@ -1,9 +1,12 @@ #include "kernel/types.h" #include "kernel/stat.h" #include "kernel/fcntl.h" +#include "kernel/param.h" #include "user/user.h" -#define MAX_PROCS 64 +// NPROC defined in param.h +#define MAX_PROCS NPROC + struct proc_data { int pid; From cfd47e97b2e6e0de687ccfb9d7d9b36043930672 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 14:13:33 -0700 Subject: [PATCH 21/34] ps works correctly but only for current pid, not pid 1 and 2 --- kernel/defs.h | 2 +- kernel/proc.c | 24 +++++++++++------------- kernel/sysproc.c | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/kernel/defs.h b/kernel/defs.h index 7f630e1..8a881a3 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -107,7 +107,7 @@ void yield(void); int either_copyout(int user_dst, uint64 dst, void *src, uint64 len); int either_copyin(void *dst, int user_src, uint64 src, uint64 len); void procdump(void); -int getprocs(struct proc_data**, int max); +int getprocs(struct proc_data*, int max); // swtch.S void swtch(struct context*, struct context*); diff --git a/kernel/proc.c b/kernel/proc.c index 9623579..013b9ad 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -690,28 +690,26 @@ procdump(void) } int -getprocs(struct proc_data **pd, int max) +getprocs(struct proc_data *pd, int max) { struct proc *p; - struct proc_data kpd[NPROC]; + struct proc_data tpd; int count = 0; - for(p = proc; p < &proc[NPROC]; p++) { + for(p = proc; p < &proc[NPROC] && count < max; p++) { if (p->state == UNUSED) { continue; } - if (count > max) { - break; - } - kpd[count].pid = p->pid; - kpd[count].ppid = p->parent ? p->parent->pid : 0; - kpd[count].state = p->state; - kpd[count].sz = p->sz; - safestrcpy(kpd[count].name, p->name, sizeof(kpd[count].name)); - printf("%s\n", kpd[count].name); + tpd.pid = p->pid; + tpd.ppid = p->parent ? p->parent->pid : 0; + tpd.state = p->state; + tpd.sz = p->sz; + safestrcpy(tpd.name, p->name, sizeof(tpd.name)); + copyout(p->pagetable, (uint64)&pd[count], (char *)&tpd, sizeof(struct proc_data)); + printf("%s\n", tpd.name); count++; } - copyout(p->pagetable, (uint64)&pd, (char *)kpd, max * sizeof(struct proc_data)); + //copyout(p->pagetable, (uint64)&pd, (char *)kpd, max * sizeof(struct proc_data)); return count; } diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 2838e2d..b155b13 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -100,5 +100,5 @@ sys_getprocs(void) { argaddr(0, (uint64 *)&pd); argint(1, &max); - return getprocs(&pd, max); + return getprocs(pd, max); } From febeddf65eb1d05052e9b6ed9ac14c738cf8cf95 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 14:17:27 -0700 Subject: [PATCH 22/34] ps basic functionality works. fixed bug in copyout --- kernel/proc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/proc.c b/kernel/proc.c index 013b9ad..4a5b0a4 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -705,11 +705,10 @@ getprocs(struct proc_data *pd, int max) tpd.state = p->state; tpd.sz = p->sz; safestrcpy(tpd.name, p->name, sizeof(tpd.name)); - copyout(p->pagetable, (uint64)&pd[count], (char *)&tpd, sizeof(struct proc_data)); + copyout(myproc()->pagetable, (uint64)&pd[count], (char *)&tpd, sizeof(struct proc_data)); printf("%s\n", tpd.name); count++; } - //copyout(p->pagetable, (uint64)&pd, (char *)kpd, max * sizeof(struct proc_data)); return count; } From e5246bde819b145da90b6f965dbe0a464b292614 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Sun, 8 Sep 2024 14:34:31 -0700 Subject: [PATCH 23/34] version 1 works! --- kernel/proc.c | 1 - user/ps.c | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/kernel/proc.c b/kernel/proc.c index 4a5b0a4..f9cc050 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -706,7 +706,6 @@ getprocs(struct proc_data *pd, int max) tpd.sz = p->sz; safestrcpy(tpd.name, p->name, sizeof(tpd.name)); copyout(myproc()->pagetable, (uint64)&pd[count], (char *)&tpd, sizeof(struct proc_data)); - printf("%s\n", tpd.name); count++; } diff --git a/user/ps.c b/user/ps.c index 9b7cefb..503e307 100644 --- a/user/ps.c +++ b/user/ps.c @@ -6,6 +6,7 @@ // NPROC defined in param.h #define MAX_PROCS NPROC +#define NELEM(x) (sizeof(x)/sizeof((x)[0])) struct proc_data { @@ -17,6 +18,16 @@ struct proc_data { }; int main (int argc, int **argv) { + // copied from procdump + static char *states[] = { + "unused", + "used", + "sleep ", + "runble", + "run ", + "zombie" + }; + char *state; struct proc_data pd[MAX_PROCS]; int tot = getprocs(pd, MAX_PROCS); @@ -30,7 +41,14 @@ int main (int argc, int **argv) { int i; for (i = 0; i < tot; i++) { - printf("%d\t%d\t%d\t%d\t%s\n",pd[i].pid, pd[i].ppid, pd[i].state,pd[i].sz, pd[i].name); + if(pd[i].state >= 0 && pd[i].state < NELEM(states) && states[pd[i].state]) { + state = states[pd[i].state]; + } + else { + state = "???"; + } + printf("%d\t%d\t%s\t%d\t%s\n", pd[i].pid, pd[i].ppid, state, pd[i].sz, pd[i].name); + } exit(0); } From 40b023fff421605eb4b07f39bc484b25d404e008 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Mon, 9 Sep 2024 10:06:26 -0700 Subject: [PATCH 24/34] updated progress --- docs/ps.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ps.txt b/docs/ps.txt index 7f97492..8e42a5b 100644 --- a/docs/ps.txt +++ b/docs/ps.txt @@ -15,7 +15,7 @@ kernel: user: - user.h (add system call) ✅ -- ps.c (new: call getprocs and output returned ptable data) ✅ (only returns number of non-UNUSED entries in proc table for now) +- ps.c (new: call getprocs and output returned ptable data) ✅ - usys.pl ✅ Future Development From 58ea1cb0c6461633f209c46224a990b6ef462a43 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Mon, 9 Sep 2024 10:11:00 -0700 Subject: [PATCH 25/34] added basic data sanitization --- kernel/proc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/proc.c b/kernel/proc.c index f9cc050..ab98e64 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -696,6 +696,10 @@ getprocs(struct proc_data *pd, int max) struct proc_data tpd; int count = 0; + if (!pd || max <= 0) { + return -1; + } + for(p = proc; p < &proc[NPROC] && count < max; p++) { if (p->state == UNUSED) { continue; From 607586078d90620710e883d10e9feb3f9519953d Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Mon, 23 Sep 2024 11:16:12 -0700 Subject: [PATCH 26/34] converted to support man docs --- docs/ps.txt | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/docs/ps.txt b/docs/ps.txt index 8e42a5b..867c71f 100644 --- a/docs/ps.txt +++ b/docs/ps.txt @@ -1,22 +1,49 @@ -**ps** displays information about active processes. The initial version will display all processes: pid, parent pid, current state, memory size, and program name. Processes in UNUSED state will be ignored. The initial version will support a -h flag for program information. +PS(1) User Commands -**Approach**: Update kernel as needed to introduce 22nd system call: getprocs and sys_getprocs. ps will pass a struct (ptable data) array pointer to the system call (getprocs). getprocs will iterate through all ptable entries where state != UNUSED and update the passed struct array pointer with ptable data via copyout. ps will output the returned ptable data in a nicely formatted manner. If the -h argument is used, ps will output simple help information and exit. +NAME +ps - report process status -**Files modified/added:* +SYNOPSIS +ps -kernel: +DESCRIPTION +The ps command displays information about active processes in the system. -- syscall.c (sys_getprocs function declaration, update syscalls) ✅ -- syscall.h (define SYS_getprocs 22) ✅ -- sysproc.c (function sys_getprocs) ✅ -- proc.c (code for getprocs) ✅ -- defs.h (function declaration)??? ✅ +OUTPUT +For each process, the following information is displayed: -user: +PID: Process ID +PPID: Parent Process ID +STATE: Current state of the process +SIZE: Size of the process in bytes +NAME: Name of the process -- user.h (add system call) ✅ -- ps.c (new: call getprocs and output returned ptable data) ✅ -- usys.pl ✅ +The STATE field can have one of the following values: +unused +used +sleep +runble (runnable) +run +zombie + +EXIT STATUS +The ps command exits 0 on success, and 1 if an error occurs. + +NOTES +This implementation of ps uses the getprocs() system call to retrieve process information. It can display information for up to NPROC processes (defined in param.h). + +EXAMPLES +To display information about all processes: +$ ps + +SEE ALSO +getprocs(2) + +BUGS +None known. + +AUTHOR +Geoffrey Weber Future Development From f571ba67137e5979e5d70495508296a3443d8169 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Mon, 23 Sep 2024 11:16:44 -0700 Subject: [PATCH 27/34] added command line param features --- user/ps.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/user/ps.c b/user/ps.c index 503e307..a6b30ec 100644 --- a/user/ps.c +++ b/user/ps.c @@ -17,7 +17,7 @@ struct proc_data { char name[16]; }; -int main (int argc, int **argv) { +int main (int argc, char *argv[]) { // copied from procdump static char *states[] = { "unused", @@ -30,6 +30,16 @@ int main (int argc, int **argv) { char *state; struct proc_data pd[MAX_PROCS]; + if(argc == 2 && strcmp(argv[1], "-h") == 0){ + printf("ps -- report process status\n"); + printf("usage: ps [-h]\n"); + printf("-h: print this helpful information\n"); + exit(0); + } else if (argc == 2) { + printf("Invalid parameter, ps -h for help\n"); + exit(1); + } + int tot = getprocs(pd, MAX_PROCS); if (tot < 0) { printf("getprocs failed\n"); From cb0f805fc31d4f5e34454f6127da60f9249db075 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Tue, 24 Sep 2024 06:15:15 -0700 Subject: [PATCH 28/34] added man pages for system call and user program --- docs/getprocs.txt | 72 ++++++++++++++++++++++++++++++++++++++++ docs/ps.txt | 83 +++++++++++++++++++++++++++-------------------- 2 files changed, 120 insertions(+), 35 deletions(-) create mode 100644 docs/getprocs.txt diff --git a/docs/getprocs.txt b/docs/getprocs.txt new file mode 100644 index 0000000..55e2b62 --- /dev/null +++ b/docs/getprocs.txt @@ -0,0 +1,72 @@ +# GETPROCS(2) System Calls Manual GETPROCS(2) + +## NAME +getprocs - get information about active processes + +## SYNOPSIS +```c +#include + +int getprocs(struct proc_data *pd, int max); +``` + +## DESCRIPTION +The `getprocs()` function retrieves information about currently active processes in the system. It populates an array of `struct proc_data` structures with details about each process, up to a maximum number specified by the caller. + +The `struct proc_data` is defined as follows: + +```c +struct proc_data { + int pid; /* Process ID */ + int ppid; /* Parent process ID */ + int state; /* Process state */ + int sz; /* Size of process memory */ + char name[16]; /* Name of the process */ +}; +``` + +The function takes two arguments: +- `pd`: A pointer to an array of `struct proc_data` where the process information will be stored. +- `max`: The maximum number of processes to retrieve information for up to NPROC processes + +## RETURN VALUE +On success, `getprocs()` returns the number of processes for which information was retrieved. This number is less than or equal to `max`. + +On error, -1 is returned. + +## ERRORS +The `getprocs()` function will fail if: +- `pd` is NULL. +- `max` is less than or equal to 0. + +## NOTES +- If `max` is greater than `NPROC` (the maximum number of processes in the system), it will be capped at `NPROC`. +- The function only retrieves information for processes that are not in the `UNUSED` state. +- The `ppid` field will be 0 if the process has no parent (i.e., for the init process). +- The process name is safely copied and null-terminated. + +## EXAMPLE +```c +#include + +#define MAX_PROCS 64 + +int main() { + struct proc_data pd[MAX_PROCS]; + int count = getprocs(pd, MAX_PROCS); + + if (count == -1) { + printf("Error calling getprocs\n"); + exit(1); + } + + for (int i = 0; i < count; i++) { + printf("PID: %d, PPID: %d, Name: %s\n", pd[i].pid, pd[i].ppid, pd[i].name); + } + + exit(0); +} +``` + +## SEE ALSO +fork(2), exec(2), wait(2), exit(2) diff --git a/docs/ps.txt b/docs/ps.txt index 867c71f..5982c6d 100644 --- a/docs/ps.txt +++ b/docs/ps.txt @@ -1,51 +1,64 @@ -PS(1) User Commands +# PS(1) User Commands PS(1) -NAME +## NAME ps - report process status -SYNOPSIS -ps +## SYNOPSIS +``` +ps [-h] +``` -DESCRIPTION -The ps command displays information about active processes in the system. +## DESCRIPTION +The `ps` utility displays information about active processes in the system. Without any options, it shows a list of all processes including their PID, PPID, state, size, and name. -OUTPUT -For each process, the following information is displayed: +## OPTIONS +-h +: Display help information and exit. -PID: Process ID -PPID: Parent Process ID -STATE: Current state of the process -SIZE: Size of the process in bytes -NAME: Name of the process +## OUTPUT +The `ps` command displays the following information for each process: -The STATE field can have one of the following values: -unused -used -sleep -runble (runnable) -run -zombie +PID +: The process ID. -EXIT STATUS -The ps command exits 0 on success, and 1 if an error occurs. +PPID +: The parent process ID. -NOTES -This implementation of ps uses the getprocs() system call to retrieve process information. It can display information for up to NPROC processes (defined in param.h). +STATE +: The current state of the process. Possible states are: + - unused: Process slot is not in use + - used: Process is allocated but not fully initialized + - sleep: Process is sleeping + - runble: Process is ready to run + - run: Process is currently running + - zombie: Process has terminated but not yet been cleaned up -EXAMPLES +SIZE +: The size of the process memory in bytes. + +NAME +: The name of the process. + +## EXIT STATUS +The `ps` utility exits 0 on success, and 1 if an error occurs. + +## EXAMPLES To display information about all processes: +``` $ ps +``` -SEE ALSO -getprocs(2) - -BUGS -None known. +To display help information: +``` +$ ps -h +``` -AUTHOR -Geoffrey Weber +## NOTES +- The `ps` command relies on the `getprocs` system call to retrieve process information. +- The maximum number of processes that can be displayed is limited by the `NPROC` constant defined in the system. -Future Development +## SEE ALSO +getprocs(2), fork(2), exec(2) -- Add support for outputting command line (argv[0]) and arguments (argv[1..n]) instead of process name. -- Add support for -t flag to output process information by parent/child in tree format +## BUGS +If an invalid state is encountered, it will be displayed as "???". From 6e571bab62d9ccb286b90fbe48713df868cb3651 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Tue, 24 Sep 2024 06:15:38 -0700 Subject: [PATCH 29/34] added tests --- kernel/proc.c | 2 ++ user/usertests.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/kernel/proc.c b/kernel/proc.c index ab98e64..0cabf18 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -700,6 +700,8 @@ getprocs(struct proc_data *pd, int max) return -1; } + max = (max > NPROC) ? NPROC : max; + for(p = proc; p < &proc[NPROC] && count < max; p++) { if (p->state == UNUSED) { continue; diff --git a/user/usertests.c b/user/usertests.c index 7d3e9bc..343e196 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -2571,6 +2571,65 @@ badarg(char *s) exit(0); } +// test to make sure getprocs returns the right number of procs + struct proc_data { + int pid; + int ppid; + int state; + int sz; + char name[16]; + }; + +void +getprocstest(char *s) +{ + struct proc_data pd_array[NPROC]; + + int tot_procs = getprocs(pd_array, NPROC); + printf("%s: getprocs test1 returned %d procs\n", s, tot_procs); + if(tot_procs < 0){ + printf("%s: getprocs test1 failed\n", s); + exit(1); + } + + if (tot_procs != 4) { + printf("%s: invalid results for getprocs test1, expected 4 procs received %d\n", s, tot_procs); + exit(1); + } + + tot_procs = getprocs(pd_array, 1); // test to find 1 proc + printf("%s: getprocs test2 returned %d procs\n", s, tot_procs); + if(tot_procs < 0){ + printf("%s: getprocs test2 failed\n", s); + exit(1); + } + + if (tot_procs != 1) { + printf("%s: invalid results for getprocs test1, expected 1 procs received %d\n", s, tot_procs); + exit(1); + } + + tot_procs = getprocs(pd_array, NPROC + 1); + printf("%s: getprocs test3 returned %d procs\n", s, tot_procs); + if(tot_procs < 0){ + printf("%s: getprocs test3 failed\n", s); + exit(1); + } + + if (tot_procs != 4) { + printf("%s: invalid results for getprocs test3, expected 4 procs received %d\n", s, tot_procs); + exit(1); + } + + tot_procs = getprocs(pd_array, 0); + if (tot_procs >= 0) { + printf("%s: invalid results for getprocs test4, expected error received %d\n", s, tot_procs); + exit(1); + } + + printf("%s: getprocs test OK\n", s); +} + struct test { void (*f)(char *); char *s; @@ -2635,6 +2694,7 @@ struct test { {sbrklast, "sbrklast"}, {sbrk8000, "sbrk8000"}, {badarg, "badarg" }, + {getprocstest, "getprocstest"}, { 0, 0}, }; From cc2e0409cca98cfb9c3d61721ff49f0c33b37964 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Wed, 25 Sep 2024 08:52:35 -0700 Subject: [PATCH 30/34] moved docs from txt to md --- docs/{getprocs.txt => getprocs.md} | 0 docs/{ps.txt => ps.md} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename docs/{getprocs.txt => getprocs.md} (100%) rename docs/{ps.txt => ps.md} (100%) diff --git a/docs/getprocs.txt b/docs/getprocs.md similarity index 100% rename from docs/getprocs.txt rename to docs/getprocs.md diff --git a/docs/ps.txt b/docs/ps.md similarity index 100% rename from docs/ps.txt rename to docs/ps.md From 8309563d9e8d1bd421ff201f3fb94286d8f72bcd Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Wed, 25 Sep 2024 11:31:10 -0700 Subject: [PATCH 31/34] added javadoc style comments --- kernel/proc.c | 23 +++++++++++++++++++++++ user/ps.c | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/kernel/proc.c b/kernel/proc.c index 0cabf18..0a407c5 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -691,6 +691,29 @@ procdump(void) int getprocs(struct proc_data *pd, int max) + /** + * Retrieves information about running processes and stores it in an array. + * + * @param pd Pointer to an array of proc_data structures where process information will be stored. + * @param max Maximum number of processes to retrieve information for. + * + * @return The number of processes for which information was retrieved, or -1 if input parameters are invalid. + * + * @details This function iterates through the process table and collects information about + * running processes. It stores this information in the provided array of proc_data + * structures. The function will retrieve information for up to 'max' processes or + * until it reaches the end of the process table (NPROC), whichever comes first. + * + * @note The function uses copyout to safely copy data to user space. + * + * @warning This function assumes that the caller has allocated sufficient memory for the + * proc_data array to hold information for 'max' processes. + */ +int +getprocs(struct proc_data *pd, int max) +{ + // Function implementation... +} { struct proc *p; struct proc_data tpd; diff --git a/user/ps.c b/user/ps.c index a6b30ec..050a809 100644 --- a/user/ps.c +++ b/user/ps.c @@ -1,3 +1,11 @@ +/** + * @file ps.c + * @brief Implementation of a simple 'ps' command for xv6. + * + * This program reports the status of processes in the system. + * -h for minimal help + */ + #include "kernel/types.h" #include "kernel/stat.h" #include "kernel/fcntl.h" From 81e99f40f535b732eb15fa5588b1fdaa8eef9036 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Wed, 25 Sep 2024 12:26:29 -0700 Subject: [PATCH 32/34] added javadoc style comment --- kernel/sysproc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel/sysproc.c b/kernel/sysproc.c index b155b13..e326dde 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -92,12 +92,21 @@ sys_uptime(void) uint64 sys_getprocs(void) { - //TODO I think this call needs to validate args passed to getprocs + /** + * Retrieves information about running processes and stores it in an array. + * + * @param pd Pointer to an array of proc_data structures where process information will be stored. + * arg[0] retrieved via argaddr + * + * @param max Maximum number of processes to retrieve information for. + * arg[1] retrieved via agrint + * + * @return The number of processes for which information was retrieved, or -1 if input parameters are invalid. + * + */ +int struct proc_data *pd; int max; - - //argaddr(int n, uint64 *ip) - argaddr(0, (uint64 *)&pd); argint(1, &max); return getprocs(pd, max); From dd5fe2bcdf579ec08deecaf925bafcc17d6b3a9c Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Thu, 26 Sep 2024 06:03:08 -0700 Subject: [PATCH 33/34] accidentally broke code adding comments --- kernel/proc.c | 7 +------ kernel/sysproc.c | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/kernel/proc.c b/kernel/proc.c index 0a407c5..c334e8d 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -708,12 +708,7 @@ getprocs(struct proc_data *pd, int max) * * @warning This function assumes that the caller has allocated sufficient memory for the * proc_data array to hold information for 'max' processes. - */ -int -getprocs(struct proc_data *pd, int max) -{ - // Function implementation... -} + **/ { struct proc *p; struct proc_data tpd; diff --git a/kernel/sysproc.c b/kernel/sysproc.c index e326dde..e8611ee 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -104,7 +104,6 @@ sys_getprocs(void) { * @return The number of processes for which information was retrieved, or -1 if input parameters are invalid. * */ -int struct proc_data *pd; int max; argaddr(0, (uint64 *)&pd); From 0ab4a9484b90ec5dc95f827f94af59824a05ee10 Mon Sep 17 00:00:00 2001 From: Geoffrey Weber Date: Thu, 26 Sep 2024 11:47:16 -0700 Subject: [PATCH 34/34] fixed error message to correct test# --- user/usertests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/usertests.c b/user/usertests.c index 343e196..1acc804 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -2605,7 +2605,7 @@ getprocstest(char *s) } if (tot_procs != 1) { - printf("%s: invalid results for getprocs test1, expected 1 procs received %d\n", s, tot_procs); + printf("%s: invalid results for getprocs test2, expected 1 procs received %d\n", s, tot_procs); exit(1); }