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;
|
402
|
24 root_process = create();
|
283
|
25 }
|
|
26
|
|
27 /*
|
|
28 Create a new process.
|
|
29 */
|
402
|
30 function process_t* create()
|
283
|
31 {
|
301
|
32 var process_t* p;
|
389
|
33
|
393
|
34 p = cast<process_t*>(memory.alloc(sizeof(process_t)));
|
283
|
35 p->id = next_pid;
|
393
|
36 p->status = 0; // Ready!
|
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 }
|
393
|
55
|
389
|
56 parent->next = p;
|
|
57 }
|
|
58
|
283
|
59 return p;
|
|
60 }
|
|
61
|
|
62
|
300
|
63 function void Kill(process_t* p)
|
283
|
64 {
|
|
65 // clean memory
|
|
66 }
|
|
67
|
300
|
68 function process_t* byId(int id)
|
292
|
69 {
|
|
70 // Perform lookup
|
|
71 return 0;
|
|
72 }
|
283
|
73
|