From 2d3597c3a02f821bb364b8ecc23fc5949fca738d Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 11:10:45 +0200 Subject: kill + ps: implement SYS_KILL (pid 1 immortal) and a ps tool - PCB gains PROC_PROG (running program id), set by exec, inherited on fork. - sys_kill(pid): reject pid 1 (immortal) and unknown/dead pids; mark the target zombie, reparent its children to init, wake its parent if blocked in wait; schedule away if a process kills itself. Reuses FindPcbByPid/ReparentToInit. - sys_ps(slot,buf)->{pid,state,prog}; sys_progname(id) via NameTable reverse lookup. NameTable gains sh/ps/kill. - libc: kill/psget/progname; tools ps (pid state cmd) and kill . - verified: ps lists sh(B)+ps(R); kill 1 refused; kill 42 fails. --- c/ps.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 c/ps.c (limited to 'c/ps.c') diff --git a/c/ps.c b/c/ps.c new file mode 100644 index 0000000..7bfc0de --- /dev/null +++ b/c/ps.c @@ -0,0 +1,14 @@ +#include "gbos.h" +/* ps: list live processes (pid, state, command). */ +void main(void) { + unsigned char i, buf[3]; + char name[9]; + for (i = 0; i < 8; i++) { + if (psget(i, buf)) { /* buf = {pid, state, prog} */ + putu(buf[0]); putc(' '); + putc("-RrBZ"[buf[1]]); putc(' '); + progname(buf[2], name); + puts(name); nl(); + } + } +} -- cgit v1.3.1-sl0p