Mercurial > lcfOS
view kernel/process.c3 @ 403:1613c9d479bf
Add top level build files
author | Windel Bouwman |
---|---|
date | Thu, 19 Feb 2015 12:17:05 +0100 |
parents | 0fb6633c42f6 |
children | 9eb1fc6aad6c |
line wrap: on
line source
module process; import memory; import kernel; // process type definition: type struct { int id; int status; process_t* next; // For linked list.. } process_t; // Or, use this list structure: // List<process_t> procs; // init is the root of all processes: var process_t* root_process; var int next_pid; function void init() { next_pid = 0; root_process = create(); } /* Create a new process. */ function process_t* create() { var process_t* p; p = cast<process_t*>(memory.alloc(sizeof(process_t))); p->id = next_pid; p->status = 0; // Ready! p->next = cast<process_t*>(0); // Increment PID: next_pid = next_pid + 1; // Store it in the list: if (root_process == cast<process_t*>(0)) { root_process = p; } else { var process_t* parent; parent = root_process; while (parent->next != cast<process_t*>(0)) { parent = parent->next; } parent->next = p; } return p; } function void Kill(process_t* p) { // clean memory } function process_t* byId(int id) { // Perform lookup return 0; }