Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hu Tianyi committed Jun 10, 2018
1 parent b3bb77b commit 4fa87d2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void userinit(void);
int wait(void);
void wakeup(void*);
void yield(void);
void reparent(int);
void reparent(int,int);

// swtch.S
void swtch(struct context**, struct context*);
Expand Down
16 changes: 13 additions & 3 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,27 @@ procdump(void)
}
}

// Make init become the proc's parent (specified by pid)
//Make parentpid become pid's parent
void
reparent(int pid)
reparent(int pid,int parentpid)
{
struct proc *p;
struct proc *parent = 0;

acquire(&ptable.lock);

for (p = ptable.proc; p < &ptable.proc[NPROC];p++){
if(p->pid == parentpid)
parent = p;
}
if(parent == 0){
release(&ptable.lock);
return;
}

for (p = ptable.proc; p < &ptable.proc[NPROC];p++){
if(p->pid == pid){
myproc()->parent = p;
p->parent = parent;
release(&ptable.lock);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ fg(char* s)
fgid = 0;
while('0' <= *s && *s <= '9')
fgid = fgid*10 + *s++ - '0';


int fgpid = 0;


}
// Execute cmd. Never returns.
Expand Down
6 changes: 5 additions & 1 deletion sysproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ int
sys_reparent(void)
{
int pid;
int parent;

if(argint(0, &pid) < 0)
return -1;
reparent(pid);
if (argint(0, &parent) < 0)
return -1;

reparent(pid,parent);
return 0;
}

0 comments on commit 4fa87d2

Please sign in to comment.