added base src
[xv6-db.git] / sysproc.c
blobefaa372d846860abf32d56462c8b4f67f6f8e385
1 #include "types.h"
2 #include "x86.h"
3 #include "defs.h"
4 #include "param.h"
5 #include "mmu.h"
6 #include "proc.h"
8 int
9 sys_fork(void)
11 return fork();
14 int
15 sys_exit(void)
17 exit();
18 return 0; // not reached
21 int
22 sys_wait(void)
24 return wait();
27 int
28 sys_kill(void)
30 int pid;
32 if(argint(0, &pid) < 0)
33 return -1;
34 return kill(pid);
37 int
38 sys_getpid(void)
40 return proc->pid;
43 int
44 sys_sbrk(void)
46 int addr;
47 int n;
49 if(argint(0, &n) < 0)
50 return -1;
51 addr = proc->sz;
52 if(growproc(n) < 0)
53 return -1;
54 return addr;
57 int
58 sys_sleep(void)
60 int n;
61 uint ticks0;
63 if(argint(0, &n) < 0)
64 return -1;
65 acquire(&tickslock);
66 ticks0 = ticks;
67 while(ticks - ticks0 < n){
68 if(proc->killed){
69 release(&tickslock);
70 return -1;
72 sleep(&ticks, &tickslock);
74 release(&tickslock);
75 return 0;
78 // return how many clock tick interrupts have occurred
79 // since boot.
80 int
81 sys_uptime(void)
83 uint xticks;
85 acquire(&tickslock);
86 xticks = ticks;
87 release(&tickslock);
88 return xticks;