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;
|
393
|
18
|
306
|
19 var int next_pid;
|
283
|
20
|
296
|
21 function void init()
|
283
|
22 {
|
|
23 next_pid = 0;
|
389
|
24 root_process = cast<process_t*>(0);
|
|
25 // init_pid = Create();
|
283
|
26 }
|
|
27
|
|
28 /*
|
|
29 Create a new process.
|
|
30 */
|
296
|
31 function process_t* Create()
|
283
|
32 {
|
301
|
33 var process_t* p;
|
389
|
34
|
393
|
35 p = cast<process_t*>(memory.alloc(sizeof(process_t)));
|
283
|
36 p->id = next_pid;
|
393
|
37 p->status = 0; // Ready!
|
389
|
38 p->next = cast<process_t*>(0);
|
|
39
|
|
40 // Increment PID:
|
300
|
41 next_pid = next_pid + 1;
|
389
|
42
|
|
43 // Store it in the list:
|
|
44 if (root_process == cast<process_t*>(0))
|
|
45 {
|
|
46 root_process = p;
|
|
47 }
|
|
48 else
|
|
49 {
|
|
50 var process_t* parent;
|
|
51 parent = root_process;
|
|
52 while (parent->next != cast<process_t*>(0))
|
|
53 {
|
|
54 parent = parent->next;
|
|
55 }
|
393
|
56
|
389
|
57 parent->next = p;
|
|
58 }
|
|
59
|
283
|
60 return p;
|
|
61 }
|
|
62
|
|
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
|