Improved shell example
This commit is contained in:
parent
596dbc6226
commit
216e66473e
@ -2,29 +2,35 @@ import io
|
|||||||
import mem
|
import mem
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
const idtype {
|
||||||
|
pid 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const state {
|
||||||
|
exited 0x4
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
length := 256
|
length := 256
|
||||||
command := mem.alloc(length)
|
command := mem.alloc(length)
|
||||||
argv := mem.alloc(1)
|
siginfo := mem.alloc(128)
|
||||||
envp := mem.alloc(1)
|
|
||||||
info := mem.alloc(24)
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
io.out("$ ")
|
io.out("λ ")
|
||||||
n := io.in(command)
|
n := io.in(command)
|
||||||
|
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
command[n-1] = '\0'
|
command[n-1] = 0
|
||||||
pid := sys.fork()
|
pid := sys.fork()
|
||||||
|
|
||||||
if pid == 0 {
|
if pid == 0 {
|
||||||
sys.execve(command, argv, envp)
|
sys.execve(command, 0, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sys.waitid(0, pid, info, 4)
|
sys.waitid(idtype.pid, pid, siginfo, state.exited)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user