root/sysproc.c
/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- sys_fork
- sys_exit
- sys_wait
- sys_kill
- sys_getpid
- sys_sbrk
- sys_sleep
- sys_uptime
1 #include "types.h"
2 #include "x86.h"
3 #include "defs.h"
4 #include "date.h"
5 #include "param.h"
6 #include "memlayout.h"
7 #include "mmu.h"
8 #include "proc.h"
9
10 int
11 sys_fork(void)
12 {
13 return fork();
14 }
15
16 int
17 sys_exit(void)
18 {
19 exit();
20 return 0; // not reached
21 }
22
23 int
24 sys_wait(void)
25 {
26 return wait();
27 }
28
29 int
30 sys_kill(void)
31 {
32 int pid;
33
34 if(argint(0, &pid) < 0)
35 return -1;
36 return kill(pid);
37 }
38
39 int
40 sys_getpid(void)
41 {
42 return proc->pid;
43 }
44
45 int
46 sys_sbrk(void)
47 {
48 int addr;
49 int n;
50
51 if(argint(0, &n) < 0)
52 return -1;
53 addr = proc->sz;
54 if(growproc(n) < 0)
55 return -1;
56 return addr;
57 }
58
59 int
60 sys_sleep(void)
61 {
62 int n;
63 uint ticks0;
64
65 if(argint(0, &n) < 0)
66 return -1;
67 acquire(&tickslock);
68 ticks0 = ticks;
69 while(ticks - ticks0 < n){
70 if(proc->killed){
71 release(&tickslock);
72 return -1;
73 }
74 sleep(&ticks, &tickslock);
75 }
76 release(&tickslock);
77 return 0;
78 }
79
80 // return how many clock tick interrupts have occurred
81 // since start.
82 int
83 sys_uptime(void)
84 {
85 uint xticks;
86
87 acquire(&tickslock);
88 xticks = ticks;
89 release(&tickslock);
90 return xticks;
91 }