void insert_process_table(struct process_table *table, pid_t pid, char *prog_name) { verify(table != NULL, "null arg table"); verify(pid > 0, "invalid process ID"); verify(prog_name != NULL, "null arg prog_name"); verify(prog_name[0] != '\0', "empty arg prog_name"); struct process *proc = Malloc(sizeof(struct process)); proc->pid = pid; proc->state = STATE_RUNNING; proc->exit_status = 0; proc->prog_name = strdup(prog_name); proc->next = NULL; if (table->head == NULL) { table->head = table->tail = proc; } else { table->tail->next = proc; table->tail = proc; } if (pr7_debug) print_process_table(table, __func__); }
void update_process_table(struct process_table *table, pid_t pid, int status) /* exit status from completed process */ { struct process *p; for (p = table->head; p != NULL; p = p->next) { if (p->pid == pid) { p->state = STATE_TERMINATED; p->exit_status = status; break; } } if (pr7_debug) print_process_table(table, __func__); }
void handle_clock_interrupt(){ CLOCK_TIME quantum_time_used = clock - process_table[current_pid].quantum_start_time; /* Check if the current process has used up its QUANTUM */ print_process_table(); if(current_pid ==-1){ run_next_process(); return; } if (quantum_time_used >= QUANTUM){ SAY2("PID %d has run for %d. That's enough. \n",current_pid, quantum_time_used); update_CPU_time_used(current_pid); process_table[current_pid].state = READY; process_table[current_pid].quantum_start_time = 0; queue_ready_process(current_pid); run_next_process(); } }
void remove_process_table(struct process_table *table, pid_t pid) { struct process *currP, *prevP; prevP = NULL; for (currP = table->head; currP != NULL; prevP = currP, currP = currP->next) { if (currP->pid == pid) // found it { if (prevP == NULL) { table->head = currP->next; } else { prevP->next = currP->next; } free(currP->prog_name); free(currP); } } if (pr7_debug) print_process_table(table, __func__); }
void pjobs() { print_process_table(__func__); }