Improved shell example

This commit is contained in:
Eduard Urbach 2025-02-16 21:30:36 +01:00
parent 596dbc6226
commit 216e66473e
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -2,29 +2,35 @@ import io
import mem
import sys
const idtype {
pid 1
}
const state {
exited 0x4
}
main() {
length := 256
command := mem.alloc(length)
argv := mem.alloc(1)
envp := mem.alloc(1)
info := mem.alloc(24)
siginfo := mem.alloc(128)
loop {
io.out("$ ")
io.out("λ ")
n := io.in(command)
if n <= 0 {
return
}
command[n-1] = '\0'
command[n-1] = 0
pid := sys.fork()
if pid == 0 {
sys.execve(command, argv, envp)
sys.execve(command, 0, 0)
return
}
sys.waitid(0, pid, info, 4)
sys.waitid(idtype.pid, pid, siginfo, state.exited)
}
}