diff kernel/process.c3 @ 402:0fb6633c42f6

Moved several files to logical locations
author Windel Bouwman
date Thu, 19 Feb 2015 00:13:07 +0100
parents kernel/src/process.c3@6ae782a085e0
children 9eb1fc6aad6c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/process.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,73 @@
+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;
+}
+