view kernel/src/process.c3 @ 389:2ec730e45ea1

Added check for recursive struct
author Windel Bouwman
date Fri, 16 May 2014 12:29:31 +0200
parents b4ac28efcdf4
children 6ae782a085e0
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 = cast<process_t*>(0);
    // init_pid = Create();
}

/*
    Create a new process.
*/
function process_t* Create()
{
    var process_t* p;
    //TODO: implement alloc:

    //= memory.Alloc(sizeof(process_t));
    p->id = next_pid;
    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


function void Kill(process_t* p)
{
    // clean memory
}

function process_t* byId(int id)
{
    // Perform lookup
    return 0;
}