Improved shell example
This commit is contained in:
parent
596dbc6226
commit
216e66473e
@ -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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user