xv6-65oo2/sysproc.c

80 lines
924 B
C

#include "types.h"
#include "defs.h"
#include "param.h"
#include "mmu.h"
#include "proc.h"
int
sys_fork(void)
{
struct proc *np;
if((np = copyproc(cp)) == 0)
return -1;
np->state = RUNNABLE;
return np->pid;
}
int
sys_exit(void)
{
exit();
return 0; // not reached
}
int
sys_wait(void)
{
return wait();
}
int
sys_kill(void)
{
int pid;
if(argint(0, &pid) < 0)
return -1;
return kill(pid);
}
int
sys_getpid(void)
{
return cp->pid;
}
int
sys_sbrk(void)
{
int addr;
int n;
if(argint(0, &n) < 0)
return -1;
if((addr = growproc(n)) < 0)
return -1;
setupsegs(cp);
return addr;
}
int
sys_sleep(void)
{
int n, ticks0;
if(argint(0, &n) < 0)
return -1;
acquire(&tickslock);
ticks0 = ticks;
while(ticks - ticks0 < n){
if(cp->killed){
release(&tickslock);
return -1;
}
sleep(&ticks, &tickslock);
}
release(&tickslock);
return 0;
}