283
|
1 module process;
|
300
|
2
|
283
|
3 import memory;
|
|
4 import kernel;
|
|
5
|
|
6 // process type definition:
|
296
|
7 type struct {
|
283
|
8 int id;
|
292
|
9 int status;
|
389
|
10 process_t* next; // For linked list..
|
283
|
11 } process_t;
|
|
12
|
292
|
13 // Or, use this list structure:
|
296
|
14 // List<process_t> procs;
|
292
|
15
|
283
|
16 // init is the root of all processes:
|
389
|
17 var process_t* root_process;
|
306
|
18 var int next_pid;
|
283
|
19
|
296
|
20 function void init()
|
283
|
21 {
|
|
22 next_pid = 0;
|
389
|
23 root_process = cast<process_t*>(0);
|
|
24 // init_pid = Create();
|
283
|
25 }
|
|
26
|
|
27 /*
|
|
28 Create a new process.
|
|
29 */
|
296
|
30 function process_t* Create()
|
283
|
31 {
|
301
|
32 var process_t* p;
|
389
|
33 //TODO: implement alloc:
|
|
34
|
301
|
35 //= memory.Alloc(sizeof(process_t));
|
283
|
36 p->id = next_pid;
|
389
|
37 p->next = cast<process_t*>(0);
|
|
38
|
|
39 // Increment PID:
|
300
|
40 next_pid = next_pid + 1;
|
389
|
41
|
|
42 // Store it in the list:
|
|
43 if (root_process == cast<process_t*>(0))
|
|
44 {
|
|
45 root_process = p;
|
|
46 }
|
|
47 else
|
|
48 {
|
|
49 var process_t* parent;
|
|
50 parent = root_process;
|
|
51 while (parent->next != cast<process_t*>(0))
|
|
52 {
|
|
53 parent = parent->next;
|
|
54 }
|
|
55 parent->next = p;
|
|
56 }
|
|
57
|
283
|
58 return p;
|
|
59 }
|
|
60
|
389
|
61 // function
|
|
62
|
283
|
63
|
300
|
64 function void Kill(process_t* p)
|
283
|
65 {
|
|
66 // clean memory
|
|
67 }
|
|
68
|
300
|
69 function process_t* byId(int id)
|
292
|
70 {
|
|
71 // Perform lookup
|
|
72 return 0;
|
|
73 }
|
283
|
74
|