This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
answers.txt
70 lines (56 loc) · 1.93 KB
/
answers.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
-------------------------------------------------------------------------------
UCLA CS 111 Minilab 1. "WeensyOS"
Professor Peter Reiher
Winter 2014
FILE: answers.txt
AUTHOR(s):
Alan Kha 904030522 akhahaha@gmail.com
-------------------------------------------------------------------------------
EXERCISE 1:
No. Scheduling another process may overwrite the eax register, which is
required to return the correct pid value.
EXERCISE 2:
// mpos-kern.c, do_fork() line 296-314
// mpos-kern.c, copy_stack() line 369-383
EXERCISE 3:
Setting a process's state to BLOCKED essentially puts it to sleep, since
schedule() only runs processes in the RUNNABLE state. After a process exits,
the waiting processes can be awakened by setting its state back to RUNNABLE,
and passing the returned value to the waiting process's eax register.
// mpos-kern.c, case INT_SYS_EXIT line 182-184
// mpos-kern.c, case INT_SYS_WAIT line 241-245
EXERCISE 4:
Set state of any processes that returned successfully to a waiting process to
EMPTY, freeing them for reuse.
// mpos-kern.c, case INT_SYS_EXIT line 185-186
// mpos-kern.c, case INT_SYS_WAIT line 239
EXERCISE 5:
void start(void)
{
int x = 0; /* note that local variable x lives on the stack */
volatile int *i = &x; // pointer to volatile integer
int *volatile j = &x; // volatile pointer to non-volatile integer
pid_t p = sys_fork();
if (p == 0) // if child process
{
i = &x; // sets i to child's x?
j = &x; // sets j to parent's x?
*i = 1;
*j = 1;
}
else if (p > 0)
sys_wait(p); // assume blocking implementation
app_printf("%d", x);
sys_exit(0);
}
EXERICSE 6:
// mpos.h, line 13
// mpos-app.h, sys_newthread() line 83-104
// mpos-kern.c, line 128
// mpos-kern.c, case INT_SYS_NEWTHREAD line 158-163
// mpos-kern.c, do_newthread() line 386-409
EXERCISE 7:
// mpos.h, line 14
// mpos-app.h, sys_kill() line 162-180
// mpos-kern.c, case INT_SYS_KILL line 191-220
// mpos-app2.h, run_child() line 64-72