diff options
Diffstat (limited to 'c')
| -rw-r--r-- | c/gbos.h | 3 | ||||
| -rw-r--r-- | c/kill.c | 10 | ||||
| -rw-r--r-- | c/libc.s | 20 | ||||
| -rw-r--r-- | c/ps.c | 14 |
4 files changed, 47 insertions, 0 deletions
@@ -38,4 +38,7 @@ unsigned char wait(void); void setin(unsigned char fd); /* redirect stdin ($FF=console) */ void setout(unsigned char fd); /* redirect stdout ($FF=console) */ unsigned char lookup(const char *name); /* command name -> program id */ +unsigned char kill(unsigned char pid); /* terminate a pid (1 is immortal)*/ +unsigned char psget(unsigned char slot, unsigned char *buf); /* {pid,state,prog}*/ +void progname(unsigned char id, char *buf); /* id -> name */ #endif diff --git a/c/kill.c b/c/kill.c new file mode 100644 index 0000000..e524627 --- /dev/null +++ b/c/kill.c @@ -0,0 +1,10 @@ +#include "gbos.h" +/* kill <pid>: terminate a process (pid 1 is immortal). */ +void main(void) { + char *argv[4]; + unsigned char argc = argv_parse(argv, 4); + unsigned char pid; + if (argc < 1) { puts("usage: kill <pid>"); nl(); return; } + pid = atou(argv[0]); + if (kill(pid)) { puts("kill: no such pid (or immortal)"); nl(); } +} @@ -167,3 +167,23 @@ _lookup: ld c, #19 ; SYS_LOOKUP rst #0x30 ret + + .globl _kill, _psget, _progname + ;; unsigned char kill(unsigned char pid /*A*/) -> A (0 ok, $FF fail) +_kill: + ld b, a + ld c, #9 ; SYS_KILL + rst #0x30 + ret + ;; unsigned char psget(unsigned char slot /*A*/, unsigned char *buf /*DE*/) -> A +_psget: + ld b, a + ld c, #20 ; SYS_PS + rst #0x30 + ret + ;; void progname(unsigned char id /*A*/, char *buf /*DE*/) +_progname: + ld b, a + ld c, #21 ; SYS_PROGNAME + rst #0x30 + ret @@ -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(); + } + } +} |
