comparison kernel/src/process.c3 @ 393:6ae782a085e0

Added init program
author Windel Bouwman
date Sat, 17 May 2014 21:17:40 +0200
parents 2ec730e45ea1
children
comparison
equal deleted inserted replaced
392:bb4289c84907 393:6ae782a085e0
13 // Or, use this list structure: 13 // Or, use this list structure:
14 // List<process_t> procs; 14 // List<process_t> procs;
15 15
16 // init is the root of all processes: 16 // init is the root of all processes:
17 var process_t* root_process; 17 var process_t* root_process;
18
18 var int next_pid; 19 var int next_pid;
19 20
20 function void init() 21 function void init()
21 { 22 {
22 next_pid = 0; 23 next_pid = 0;
28 Create a new process. 29 Create a new process.
29 */ 30 */
30 function process_t* Create() 31 function process_t* Create()
31 { 32 {
32 var process_t* p; 33 var process_t* p;
33 //TODO: implement alloc:
34 34
35 //= memory.Alloc(sizeof(process_t)); 35 p = cast<process_t*>(memory.alloc(sizeof(process_t)));
36 p->id = next_pid; 36 p->id = next_pid;
37 p->status = 0; // Ready!
37 p->next = cast<process_t*>(0); 38 p->next = cast<process_t*>(0);
38 39
39 // Increment PID: 40 // Increment PID:
40 next_pid = next_pid + 1; 41 next_pid = next_pid + 1;
41 42
50 parent = root_process; 51 parent = root_process;
51 while (parent->next != cast<process_t*>(0)) 52 while (parent->next != cast<process_t*>(0))
52 { 53 {
53 parent = parent->next; 54 parent = parent->next;
54 } 55 }
56
55 parent->next = p; 57 parent->next = p;
56 } 58 }
57 59
58 return p; 60 return p;
59 } 61 }
60
61 // function
62 62
63 63
64 function void Kill(process_t* p) 64 function void Kill(process_t* p)
65 { 65 {
66 // clean memory 66 // clean memory