【发布时间】:2020-04-03 02:10:30
【问题描述】:
我已经完成了创建系统调用的所有步骤,然后创建了一个用户程序并运行它:
proc.c
int countChildren (int pid) {
struct proc *p;
int count = 0;
acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
if(p->parent->pid == pid) count++;
release(&ptable.lock);
return count;
}
sysproc.c
int
sys_getchildren(void)
{
int pid;
argint(0, &pid);
return countChildren(pid);
}
userProgram.c
...
#include "types.h"
#include "user.h"
int main (void) {
int n1 = fork();
int n2 = fork();
int n3 = fork();
int n4 = fork();
if (n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0) {
printf(1,"parent\n");
printf(1," getchildren = %d \n", getchildren());
}
exit();
}
但是结果不是我所期望的,下面是结果:
【问题讨论】:
标签: c process operating-system xv6