Thread: Software Simulatior

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    You should define a global datastructure which will be accessed by the processes. When a process starts, it must update the datastructure and when it finishes it must update the datastructure. The datastructure could be a linked list which elements look like this:

    Code:
    struct time_table_element
    {
        int process_id;
        struct time start_time;
        struct time stop_time;
        struct time_table_element *next;
    };
    To make difference between the processes, each proces should have an unique ID. When a process starts, it puts its ID in the process_id and the current system time in start_time. When it finishes, it current system time in stop_time.

    I assume you are writing a scheduler which takes care of the round-robin algorithm you seem to use. This scheduler should also extend the time-table with a new element. This does take time, perhaps easier would be to implement a fixed time-table, like:

    Code:
    struct time_table_element
    {
        int process_id;
        struct time start_time;
        struct time stop_time;
    };
    
    struct time_table_element time_table [NR_OF_ELEMENTS];
    This requires you to have another global variable for keeping the index. The scheduler should update the index by increasing it by one each time a new process is starting. It should also check that no more elements can be stored than the maximum.

    BTW, what OS are you using?

    [edit]
    Since the processes are running parallel, you must make sure that no two processes can access the global data for writing at same time. To solve this you could implement a semaphore mechanism.

    Note that the time-table now can look like:

    00:00:02 process A start
    00:00:08 process B start
    00:00:10 process B stop
    00:00:16 process C start
    00:00:20 process A stop
    00:00:26 process C stop

    And you problably don't implement the scheduler,don't you? So your processes need to update the datastructure.
    [/edit]
    Last edited by Shiro; 06-20-2002 at 01:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Software Design/Test - Redmond, WA
    By IRVolt in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 06-11-2008, 10:26 AM
  2. Why C Matters
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 136
    Last Post: 01-16-2008, 09:09 AM
  3. Adding trial period to software
    By BobS0327 in forum C Programming
    Replies: 17
    Last Post: 01-03-2006, 02:13 PM
  4. software licences
    By trekker in forum Tech Board
    Replies: 3
    Last Post: 06-17-2003, 08:37 AM