I have an assignment where we are supposed to populate an operating system's ready queue with processes and try various process scheduling scheme and record their wait times. To do this i made a rudimentary structure for a process:

typedef struct{
         int ID;
         int wait_time;
         int exec_time;

inside a process.h file. I have 3 other source files, queue.h, queue.c and processmanager.c.

Queue.h looks like this

#ifndef QUEUE_H
#define QUEUE_H
#include <stdbool.h>
#include "process.h"

typedef struct linked_list *Queue;

Queue create(void);
void destroy(Queue q);
bool is_empty(Queue q);
bool is_full(Queue q);
void enqueue(Queue q, process *p);
struct node *dequeue(Queue q);
void print_node_element(struct node *p);
void print_queue(Queue q);
float *get_process_distribution(Queue q);
process *fcfs(Queue q);

so a Queue type is a pointer to a linked_list struct, which uses struct nodes which looks like this:

struct node{
         process *element;
         struct node *next;

      struct linked_list{
          struct node *head;
          struct node *tail;
          int size;

The reason for all the files is because I really wanted to make a Queue ADT, with a high level of abstraction, because personally I like abstraction.

Anyway, the first algorithm I made, a first come first served kind, works fine in that it updates wait times, and I'm pretty sure i got it to populate an array of pointers to structures.

 * fcfs: a nonpreemptive first come-first served algorithm
 * returns an array of pointers to processes that have the state
 * of the queue represented in it (IDs wait times, execute times)
process *fcfs(Queue q)
   process *state_of_queue[q->size]; 
   int state_counter = 0;
           struct node *n = dequeue(q);
           state_of_queue[state_counter] = n->element;
           int i;
           for(i = 0; i < n->element->exec_time; i++){
                struct node *temp = q->head;
                while(temp != NULL){
                    temp = temp->next;
   return state_of_queue[0];

I chose an array of pointers to structures because it seemed elegant and more efficient than making an entire array of processes.

In my client program, I have the line:

process *state_of_queue = fcfs(q);

My understanding is that it returns a pointer to the first index of an array of pointers, where the pointers point to structures.

Any ideas how i can access the members of the structures that are being pointed to? I was tossing around the idea of making the function return process **, and other than that I have no idea how to access the structures. I've tried everything i could think of. I would really appreciate some help.

If this points to a structure..

process *state_of_queue = fcfs(q);

Then use




also i kind of want to edit that last post.

process *q = fcfs(q); shouldn't point to a structure. It should point to a pointer to a structure.

This article has been dead for over six months. Start a new discussion instead.