接續昨天的題目
原本今天打算寫完這題的,但一直卡在一個地方,
就先貼出我寫到一半的成果吧
// kernel/sysproc.c
uint64
sys_sysinfo(void)
{
uint64 info;
struct sysinfo kinfo;
struct proc *p = myproc();
if(argaddr(0, &info) < 0)
return -1;
kinfo.freemem = freemem();
kinfo.nproc = nproc();
if(copyout(p->pagetable, info, (char *)&kinfo, sizeof(info)) < 0)
return -1;
return 0;
}
// kernel/kalloc.c
uint64
freemem(void)
{
uint64 npage = 0;
struct run *r;
r = kmem.freelist;
while (r) {
npage++;
r = r->next;
}
return npage * PGSIZE;
}