fixed pointer issues
This commit is contained in:
parent
6abe829fdb
commit
d843d4d068
50
simulator.c
50
simulator.c
@ -42,20 +42,20 @@ void print_pinfo(struct pinfo * info) {
|
|||||||
printf(" Arrival time: %d\n", info->arrival_time);
|
printf(" Arrival time: %d\n", info->arrival_time);
|
||||||
printf(" Execution time: %d\n", info->execution_time);
|
printf(" Execution time: %d\n", info->execution_time);
|
||||||
printf(" Priority: %d\n", info->priority);
|
printf(" Priority: %d\n", info->priority);
|
||||||
|
printf(" NEXT -> %p\n", info->next_pinfo);
|
||||||
printf("}>\n");
|
printf("}>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pinfo create_process(int id, int arrival_time, int execution_time, int priority) {
|
struct pinfo * create_process(int id, int arrival_time, int execution_time, int priority) {
|
||||||
struct pinfo info = {
|
struct pinfo * info = malloc(sizeof(struct pinfo));
|
||||||
id,
|
info->id = id;
|
||||||
arrival_time,
|
info->arrival_time = arrival_time;
|
||||||
execution_time,
|
info->execution_time = execution_time;
|
||||||
priority,
|
info->priority = priority;
|
||||||
0,
|
info->wait_time = 0;
|
||||||
0,
|
info->completion_time = 0;
|
||||||
WAITING,
|
info->state = WAITING;
|
||||||
NULL
|
info->next_pinfo = NULL;
|
||||||
};
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ struct pinfo * read_file() {
|
|||||||
|
|
||||||
struct pinfo * first = NULL;
|
struct pinfo * first = NULL;
|
||||||
struct pinfo * last = NULL;
|
struct pinfo * last = NULL;
|
||||||
struct pinfo process;
|
struct pinfo * process;
|
||||||
|
|
||||||
while (fgets(line, buf_size, file)) {
|
while (fgets(line, buf_size, file)) {
|
||||||
pid_str = strtok(line, " ");
|
pid_str = strtok(line, " ");
|
||||||
@ -110,17 +110,18 @@ struct pinfo * read_file() {
|
|||||||
|
|
||||||
// If linked list not initialized
|
// If linked list not initialized
|
||||||
if (first == NULL) {
|
if (first == NULL) {
|
||||||
first = &process;
|
first = process;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is an element in list
|
// If there is an element in list
|
||||||
if (last != NULL) {
|
if (last != NULL) {
|
||||||
last->next_pinfo = &process;
|
last->next_pinfo = process;
|
||||||
}
|
}
|
||||||
last = &process;
|
last = process;
|
||||||
|
|
||||||
print_pinfo(&process);
|
print_pinfo(process);
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
@ -129,13 +130,24 @@ void write_file(struct pinfo * process, struct perf_info * perf) {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_processes(struct pinfo * next) {
|
||||||
|
struct pinfo * cur;
|
||||||
|
while (next != NULL) {
|
||||||
|
cur = next;
|
||||||
|
next = cur->next_pinfo;
|
||||||
|
free(cur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
struct pinfo * processes = read_file();
|
struct pinfo * processes = read_file();
|
||||||
|
|
||||||
/*struct perf_info perf = schedule_FCFS(processes);
|
//struct perf_info perf = schedule_FCFS(processes);
|
||||||
|
|
||||||
write_file(processes, &perf);
|
//write_file(processes, &perf);
|
||||||
print_perf(perf);*/
|
//print_perf(&perf);
|
||||||
|
|
||||||
|
free_processes(processes);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user