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. --- include/gbos.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include/gbos.inc') diff --git a/include/gbos.inc b/include/gbos.inc index 6aaaf73..30c3a50 100644 --- a/include/gbos.inc +++ b/include/gbos.inc @@ -69,8 +69,11 @@ DEF PROC_PARENT RB 1 DEF PROC_EXIT RB 1 ; exit code (valid when PS_ZOMBIE) DEF PROC_STDIN RB 1 ; $FF = console, else an open-file fd DEF PROC_STDOUT RB 1 ; $FF = console, else an open-file fd +DEF PROC_PROG RB 1 ; program id currently running ($FF = none), for ps DEF PROC_SIZE RB 0 +DEF KILL_CODE EQU 137 ; exit status of a killed process (128 + SIGKILL) + DEF STD_CONSOLE EQU $FF ; ----------------------------------------------------------------------------- @@ -96,7 +99,10 @@ DEF SYS_PUTC EQU 16 ; write a byte to stdout (E=byte) DEF SYS_SETIN EQU 17 ; set current stdin fd (B=fd, $FF=console) DEF SYS_SETOUT EQU 18 ; set current stdout fd (B=fd, $FF=console) DEF SYS_LOOKUP EQU 19 ; program id for a command name (DE=name -> A=id/$FF) -DEF SYS_MAX EQU 20 +DEF SYS_PS EQU 20 ; process table entry (B=slot, DE=buf3 -> A=1/0) +DEF SYS_PROGNAME EQU 21 ; program id -> name (B=id, DE=namebuf) +DEF SYS_MAX EQU 22 +; SYS_KILL (9) is now implemented (B=pid -> A=0/$FF; pid 1 is immortal) ; (SYS_OPEN=4 / SYS_CLOSE=5 are now implemented by the filesystem) ; ----------------------------------------------------------------------------- @@ -138,5 +144,8 @@ DEF PROG_ARGS EQU 12 DEF PROG_LS EQU 13 DEF PROG_SAVE EQU 14 DEF PROG_RM EQU 15 +DEF PROG_PS EQU 16 +DEF PROG_KILL EQU 17 +DEF PROG_SPIN EQU 18 ENDC -- cgit v1.3.1-sl0p