Support exit status for exit/wait
One test case for returning a exit status Passes usertests, but haven't used it to simplify tests
This commit is contained in:
parent
035cca95fe
commit
7e6c37e67e
22 changed files with 319 additions and 297 deletions
|
|
@ -141,6 +141,7 @@ freeproc(struct proc *p)
|
|||
p->name[0] = 0;
|
||||
p->chan = 0;
|
||||
p->killed = 0;
|
||||
p->xstate = 0;
|
||||
p->state = UNUSED;
|
||||
}
|
||||
|
||||
|
|
@ -319,7 +320,7 @@ reparent(struct proc *p, struct proc *parent) {
|
|||
// An exited process remains in the zombie state
|
||||
// until its parent calls wait().
|
||||
void
|
||||
exit(void)
|
||||
exit(int status)
|
||||
{
|
||||
struct proc *p = myproc();
|
||||
|
||||
|
|
@ -350,6 +351,7 @@ exit(void)
|
|||
// Parent might be sleeping in wait().
|
||||
wakeup1(p->parent);
|
||||
|
||||
p->xstate = status;
|
||||
p->state = ZOMBIE;
|
||||
|
||||
release(&p->parent->lock);
|
||||
|
|
@ -362,7 +364,7 @@ exit(void)
|
|||
// Wait for a child process to exit and return its pid.
|
||||
// Return -1 if this process has no children.
|
||||
int
|
||||
wait(void)
|
||||
wait(uint64 addr)
|
||||
{
|
||||
struct proc *np;
|
||||
int havekids, pid;
|
||||
|
|
@ -387,6 +389,12 @@ wait(void)
|
|||
if(np->state == ZOMBIE){
|
||||
// Found one.
|
||||
pid = np->pid;
|
||||
if(addr != 0 && copyout(p->pagetable, addr, (char *)&np->xstate,
|
||||
sizeof(np->xstate)) < 0) {
|
||||
release(&np->lock);
|
||||
release(&p->lock);
|
||||
return -1;
|
||||
}
|
||||
freeproc(np);
|
||||
release(&np->lock);
|
||||
release(&p->lock);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue