static void free_process (gpointer data) { process_t *process = data; destroy_process (process); }
void remove_endpoint_handle(EndpointHandle * endpointHandle) { destroy_process(endpointHandle->process); DEST_SPINLOCK(&endpointHandle->endpoint->lock); FREE(endpointHandle->endpoint); FREE(endpointHandle); }
void _exit(int _exitcode) { //kprintf("PID %d exitcode %d\n", curthread->t_pid, _exitcode); // lock_acquire(parray_lock); // parray[curthread->t_pid].exitcode = _exitcode; // parray[curthread->t_pid].self = NULL; // parray[curthread->t_pid].occupied = 0; // lock_release(parray_lock); destroy_process(_exitcode); //kprintf("PID %d done exit\n", curthread->t_pid); thread_exit(); }
void purge_proc_list(){ process *p; process *p_prev; process *p_next; for (p = first_process; p; p=p->next){ if (p->completed){ p_prev = p->prev; p_next = p->next; p_prev->next = p_next; if(p_next) p_next->prev = p_prev; destroy_process(p); } } }
int main(int argc, char *argv[]) { //check for correct usage if (argc < 2) { printf("The correct usage is ./proja <filename>\n"); perror("Incorrect usage of program!! exiting!!\n"); return -1; } init_process(); char *filename = argv[1]; //1. read the input parameter file read_input_file(filename); sleep(2);//to see if that helps the last client being stuck at infinite loop destroy_process(); return 0; }
static int parse_client_line(const int client_socket, char *msg) { char *token; /* On récupère le premier mot, s'il est vide, on retourne direct */ if (!(token = strtok(msg, " "))) return MSG_OK; /***************************************************************************** * CMD_QUIT ****************************************************************************/ if (!strcmp(CMD_QUIT, token)) { send_ok(client_socket, DETAIL_RET_QUIT); return MSG_QUIT; } /***************************************************************************** * CMD_CREATE_PROCESS ****************************************************************************/ else if (!strcmp(CMD_CREATE_PROCESS, token)) { char *args[MAX_ARGS]; char **pc = args; /* On récup le nom du prog */ if (!(token = strtok(NULL, " "))) { send_failure(client_socket, DETAIL_RET_CREATE_PROCESS_SYNTAX); return MSG_ERR; } /* strtok renvoie un buffer static, on le copie */ /* *pc = args[0] = nom du programme */ if (!(*pc++ = strdup(token))) { perror("strdup"); return MSG_ERR; } /* La suite devient optionelle, c'est les arguments */ while ((token = strtok(NULL, " "))) { if ((*pc++ = strdup(token)) == NULL) { perror("strdup"); return MSG_ERR; } } *pc = NULL; /* Fin des arguments */ /* On crée le processus */ pid_t proc = create_process(args[0], args); /* Le processus n'a pas pu être créé */ if (proc == -1) { send_failure(client_socket, DETAIL_RET_CREATE_PROCESS_ERROR); return MSG_ERR; } send_ok(client_socket, itoa(proc)); return MSG_OK; } /***************************************************************************** * CMD_DESTROY_PROCESS ****************************************************************************/ else if (!strcmp(CMD_DESTROY_PROCESS, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_DESTROY_PROCESS_SYNTAX); return MSG_ERR; } pid_t process_to_kill = atoi(token); if (!process_exists(process_to_kill)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } destroy_process(process_to_kill); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_SEND_INPUT ****************************************************************************/ else if (!strcmp(CMD_SEND_INPUT, token)) { char buffer[MESSAGE_BUFFER_SIZE]; buffer[0] = '\0'; /* On récup le PID */ if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_SEND_INPUT_SYNTAX); return MSG_ERR; } /* Il existe ? */ pid_t send_to_process = atoi(token); if (!process_exists(send_to_process)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } /* Il est déjà terminé ? */ if (get_return_code(send_to_process) != PROCESS_NOT_TERMINATED) { send_failure(client_socket, DETAIL_RET_PROCESS_TERMINATED); return MSG_ERR; } /* Son stdin est ouvert ? */ if (!input_open(send_to_process)) { send_failure(client_socket, DETAIL_RET_INPUT_CLOSE); return MSG_ERR; } /* On récup' le message à envoyer */ /* TODO: Prendre la chaîne telle qu'elle, sans splitter puis merger avec un espace */ while ((token = strtok(NULL, " "))) { strcat(buffer, token); strcat(buffer, " "); } /* Si le message est vide, erreur ! */ if (strlen(buffer) == 0) { send_failure(client_socket, DETAIL_RET_SEND_INPUT_SYNTAX); return MSG_ERR; } /* Sinon on envoie ! */ send_input(send_to_process, buffer); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_CLOSE_INPUT ****************************************************************************/ else if (!strcmp(CMD_CLOSE_INPUT, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_CLOSE_INPUT_SYNTAX); return MSG_ERR; } pid_t process_to_close_input = atoi(token); if (!process_exists(process_to_close_input)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } close_input(process_to_close_input); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_OUTPUT ****************************************************************************/ else if (!strcmp(CMD_GET_OUTPUT, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_GET_OUTPUT_SYNTAX); return MSG_ERR; } pid_t process_to_get_output = atoi(token); if (!process_exists(process_to_get_output)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } get_output(client_socket, process_to_get_output); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_ERROR ****************************************************************************/ else if (!strcmp(CMD_GET_ERROR, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_GET_ERROR_SYNTAX); return MSG_ERR; } pid_t process_to_get_error = atoi(token); if (!process_exists(process_to_get_error)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } get_error(client_socket, process_to_get_error); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_RETURN_CODE ****************************************************************************/ else if (!strcmp(CMD_GET_RETURN_CODE, token)) { if ((token = strtok(NULL, " ")) == NULL) { send_failure(client_socket, DETAIL_RET_GET_RETURN_CODE_SYNTAX); return MSG_ERR; } pid_t process_to_get_ret = atoi(token); if (!process_exists(process_to_get_ret)) { send_failure(client_socket, DETAIL_RET_UNKNOWN_PROCESS); return MSG_ERR; } int ret = get_return_code(process_to_get_ret); if (ret == PROCESS_NOT_TERMINATED) { send_failure(client_socket, DETAIL_RET_GET_RETURN_CODE_ERROR); return MSG_ERR; } send_ok(client_socket, itoa(ret)); return MSG_OK; } /***************************************************************************** * CMD_LIST_PROCESS ****************************************************************************/ else if (!strcmp(CMD_LIST_PROCESS, token)) { list_process(client_socket); send_ok(client_socket, NULL); return MSG_OK; } /***************************************************************************** * CMD_GET_HELP ****************************************************************************/ else if (!strcmp(CMD_GET_HELP, token)) { send_basic(client_socket, help, strlen(help)); return MSG_OK; } /***************************************************************************** * COMMANDE INCONNUE ****************************************************************************/ else { send_failure(client_socket, DETAIL_RET_UNKNOWN_COMMAND); return MSG_UNKNOWN_COMMAND; } }