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. --- src/proc.asm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/proc.asm') diff --git a/src/proc.asm b/src/proc.asm index ab1c807..cd79160 100644 --- a/src/proc.asm +++ b/src/proc.asm @@ -224,7 +224,9 @@ ProcCreate:: ld [hl+], a ; PROC_EXIT ld a, STD_CONSOLE ld [hl+], a ; PROC_STDIN = console - ld [hl], a ; PROC_STDOUT = console + ld [hl+], a ; PROC_STDOUT = console + ld a, $FF + ld [hl], a ; PROC_PROG = none ; build the initial stack frame in the task's RAM bank ld a, [wTmpEntry] @@ -453,7 +455,10 @@ sys_fork:: ld [hl+], a ; child STDIN = parent STDIN inc de ld a, [de] - ld [hl], a ; child STDOUT = parent STDOUT + ld [hl+], a ; child STDOUT = parent STDOUT + inc de + ld a, [de] + ld [hl], a ; child PROC_PROG = parent PROC_PROG ; ---- return to the parent with child pid ---- ld a, [wForkUserSP] @@ -484,6 +489,15 @@ sys_fork:: ; our demo programs keep no pre-initialized RAM. ; ============================================================================= sys_exec:: + ; record the running program id in the PCB (for ps) + ld a, [wCurProc] + add PROC_PROG + ld l, a + ld a, [wCurProc+1] + adc 0 + ld h, a + ld a, b + ld [hl], a ; HL = &ProgramTable[B] = ProgramTable + B*4 ld hl, ProgramTable ld a, b -- cgit v1.3.1-sl0p