int main(int argc, char *argv[]) { if (argc == 1) { fprintf(stderr, "please supply at least one command to run\n"); return 1; } install_term_and_int_handlers(); pid_t cmds[MAX_CMDS]; int n_cmds = 0; { char **cmd_end = argv + argc; char **arg_it = argv + 1; int wait_on_command = 1; int wait_on_all_commands = 1; // TODO: parse more commands, including -h/--help with getopt if (! strcmp(*arg_it, "-f")) { ++arg_it; wait_on_all_commands = 0; } char **cmd_begin = arg_it; for (; arg_it < cmd_end; ++arg_it) { if (! strcmp(*arg_it, SEP)) { *arg_it = 0; // replace with null to terminate when passed to execvp if (wait_on_command) cmds[n_cmds++] = run_proc(cmd_begin); else run_proc(cmd_begin); cmd_begin = arg_it + 1; wait_on_command = wait_on_all_commands; } } if (cmd_begin < cmd_end) { if (wait_on_command) cmds[n_cmds++] = run_proc(cmd_begin); else run_proc(cmd_begin); wait_on_command = wait_on_all_commands; } } int error_code = wait_for_requested_commands_to_exit(n_cmds, cmds); remove_term_and_int_handlers(); alarm(WAIT_FOR_PROC_DEATH_TIMEOUT); kill(0, SIGTERM); wait_for_all_processes_to_exit(error_code); # ifndef NDEBUG fprintf(stderr, "all processes exited cleanly\n"); # endif return error_code; }
/** Constructor. * @param progname name of program, component name for logging * @param file file to execute, can be a program in the path or a * fully qualified path * @param argv array of arguments for the process, the last element * must be NULL * @param envp array of environment variables for the process, the * last element must be NULL. Can be NULL to omit. */ SubProcess::SubProcess(const char *progname, const char *file, const char *argv[], const char *envp[]) : progname_(progname), io_service_work_(io_service_), logger_(NULL), sd_stdin_(io_service_), sd_stdout_(io_service_), sd_stderr_(io_service_) { io_service_thread_ = std::thread([this]() { this->io_service_.run(); }); run_proc(file, argv, envp); }
static bool MinidumpCallback(const wchar_t *minidump_folder, const wchar_t *minidump_id, void *context, EXCEPTION_POINTERS*, MDRawAssertionInfo*, bool) { ExceptionManager* this_ptr = reinterpret_cast<ExceptionManager*>(context); report_info("Detected crash..."); std::string minidump_path = utf8::cvt<std::string>(minidump_folder) + "\\" + utf8::cvt<std::string>(minidump_id) + ".dmp"; if (minidump_path.length() >= MAX_PATH) { report_error("Path to long"); return false; } if (!boost::filesystem::is_regular(minidump_path)) { report_error("Failed to create mini dump please check that you have a proper version of dbghlp.dll"); return false; } std::string path = modulePath() + "\\reporter.exe"; if (path.length() >= MAX_PATH) { report_error("Path to long"); return false; } if (!boost::filesystem::is_regular(path)) { report_error("Failed to find reporter.exe"); return false; } if (this_ptr->is_archive()) { run_command(this_ptr, path, "archive", minidump_path, this_ptr->target()); } if (this_ptr->is_send()) { if (this_ptr->is_send_ui()) run_command(this_ptr, path, "send-gui", minidump_path, this_ptr->target()); else run_command(this_ptr, path, "send", minidump_path, this_ptr->target()); } #ifdef WIN32 if (this_ptr->is_restart()) { std::vector<std::string> commands; try { if (!serviceControll::isStarted(utf8::cvt<std::wstring>(this_ptr->service()))) { report_error("Service not started, not restarting..."); return true; } } catch (...) { report_error("Failed to check service state"); } commands.push_back(path); commands.push_back("restart"); commands.push_back(this_ptr->service()); run_proc(build_commandline(commands)); } #endif return true; }
void run_command(ExceptionManager* this_ptr, std::string exe, std::string command, std::string minidump, std::string target) { std::vector<std::string> commands; commands.push_back(exe); commands.push_back(command); commands.push_back(minidump); commands.push_back(this_ptr->application()); commands.push_back(this_ptr->version()); commands.push_back(this_ptr->date()); commands.push_back(target); run_proc(build_commandline(commands)); Sleep(500); }
void SubProcess::run_proc(const char *file, const char *argv[], const char *envp[]) { pid_ = run_proc(file, argv, envp, pipe_stdin_w_, pipe_stdout_r_, pipe_stderr_r_); sd_stdin_.assign(dup(pipe_stdin_w_)); sd_stdout_.assign(dup(pipe_stdout_r_)); sd_stderr_.assign(dup(pipe_stderr_r_)); if (logger_) { start_log(progname_.c_str(), Logger::LL_INFO, sd_stdout_, buf_stdout_); start_log(progname_.c_str(), Logger::LL_WARN, sd_stderr_, buf_stderr_); } }
int main(void){ queue* priority_queue=(queue*)malloc(sizeof(queue*)); priority_queue->head=NULL; priority_queue->tail=NULL; //Open file aznd ready for reading FILE *f; f = fopen("processes_q5.txt","r"); char line[1024]; const char* s=", "; char *token; char* t_name[256]; int* t_data[3]; //Read in CSV file while(fgets(line,1024,f)){ token = strtok(line, s); for(int i=0;i<3;i++) { if(i==0) { strcpy(t_name,token); } else { token = strtok(NULL, s); t_data[i]=atoi(token); } } //Create process proc new_proc = (proc){.name="",.priority=t_data[1],.pid=0,.runtime=t_data[2]}; strcpy(new_proc.name,t_name); printf("Creating Process Priority: %d\n",new_proc.priority); push(priority_queue,new_proc); } proc* process = pop(priority_queue); while(process){ run_proc(process); process=pop(priority_queue); } free(priority_queue); }
/** * Runs all commands marked with -c and waits for them to exit. */ static void run_configure_cmds(int n_cmds, Cmd *cmds) { int run_configure_cmds = 0; for (int i = 0; i < n_cmds; ++i) { if (! cmds[i].configuring) continue; cmds[i].pid = run_proc(cmds[i].args); ++run_configure_cmds; } if (run_configure_cmds) { DPRINTF("waiting for configuration commands to exit"); int status; for (;;) { if (waitpid(-1, &status, 0) == -1 && errno == ECHILD) break; } DPRINTF("all configuration commands have exited"); } }
/* * loaddb_internal - internal main loaddb function * return: NO_ERROR if successful, error code otherwise * argc(in): argc of main * argv(in): argv of main * dba_mode(in): */ static int loaddb_internal (UTIL_FUNCTION_ARG * arg, int dba_mode) { UTIL_ARG_MAP *arg_map = arg->arg_map; int error = NO_ERROR; /* set to static to avoid copiler warning (clobbered by longjump) */ static FILE *schema_file = NULL; static FILE *index_file = NULL; static FILE *object_file = NULL; FILE *error_file = NULL; int status = 0; int errors, objects, defaults; #if !defined (LDR_OLD_LOADDB) int lastcommit = 0; #endif /* !LDR_OLD_LOADDB */ char *passwd; /* set to static to avoid copiler warning (clobbered by longjump) */ static int interrupted = false; int au_save = 0; extern bool obt_Enable_autoincrement; char log_file_name[PATH_MAX]; LOADDB_INIT_DEBUG (); obt_Enable_autoincrement = false; Volume = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0); Input_file = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1); User_name = utility_get_option_string_value (arg_map, LOAD_USER_S, 0); Password = utility_get_option_string_value (arg_map, LOAD_PASSWORD_S, 0); Syntax_check = utility_get_option_bool_value (arg_map, LOAD_CHECK_ONLY_S); Load_only = utility_get_option_bool_value (arg_map, LOAD_LOAD_ONLY_S); Estimated_size = utility_get_option_int_value (arg_map, LOAD_ESTIMATED_SIZE_S); Verbose = utility_get_option_bool_value (arg_map, LOAD_VERBOSE_S); Disable_statistics = utility_get_option_bool_value (arg_map, LOAD_NO_STATISTICS_S); Periodic_commit = utility_get_option_int_value (arg_map, LOAD_PERIODIC_COMMIT_S); Verbose_commit = Periodic_commit > 0 ? true : false; No_oid_hint = utility_get_option_bool_value (arg_map, LOAD_NO_OID_S); Schema_file = utility_get_option_string_value (arg_map, LOAD_SCHEMA_FILE_S, 0); Index_file = utility_get_option_string_value (arg_map, LOAD_INDEX_FILE_S, 0); Object_file = utility_get_option_string_value (arg_map, LOAD_DATA_FILE_S, 0); Error_file = utility_get_option_string_value (arg_map, LOAD_ERROR_CONTROL_FILE_S, 0); Ignore_logging = utility_get_option_bool_value (arg_map, LOAD_IGNORE_LOGGING_S); #if !defined (LDR_OLD_LOADDB) Ignore_class_file = utility_get_option_string_value (arg_map, LOAD_IGNORE_CLASS_S, 0); #endif Input_file = Input_file ? Input_file : ""; Schema_file = Schema_file ? Schema_file : ""; Index_file = Index_file ? Index_file : ""; Object_file = Object_file ? Object_file : ""; Error_file = Error_file ? Error_file : ""; if (ldr_validate_object_file (stderr, arg->argv0)) { goto error_return; } /* error message log file */ sprintf (log_file_name, "%s_%s.err", Volume, arg->command_name); er_init (log_file_name, ER_NEVER_EXIT); if (Index_file[0] != '\0' && PRM_SR_NBUFFERS < LOAD_INDEX_MIN_SORT_BUFFER_PAGES) { sysprm_set_force (PRM_NAME_SR_NBUFFERS, LOAD_INDEX_MIN_SORT_BUFFER_PAGES_STRING); } sysprm_set_force (PRM_NAME_JAVA_STORED_PROCEDURE, "no"); /* login */ if (User_name != NULL || !dba_mode) { (void) db_login (User_name, Password); if ((error = db_restart (arg->command_name, true, Volume))) { if (error == ER_AU_INVALID_PASSWORD) { /* prompt for password and try again */ error = NO_ERROR; passwd = getpass (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_PASSWORD_PROMPT)); if (!strlen (passwd)) passwd = NULL; (void) db_login (User_name, passwd); error = db_restart (arg->command_name, true, Volume); } } } else { /* if we're in the protected dba mode, just login without authorization */ AU_DISABLE_PASSWORDS (); db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY); (void) db_login ("dba", NULL); error = db_restart (arg->command_name, true, Volume); } /* open loaddb log file */ sprintf (log_file_name, "%s_loaddb.log", Volume); loaddb_log_file = fopen (log_file_name, "w+"); if (loaddb_log_file == NULL) { printf ("Cannot open log file %s\n", log_file_name); status = 2; goto error_return; } #if 0 #if !defined (LDR_OLD_LOADDB) /* Execute old loaddb if no optimization flag is set true * or LOADDB_NOPT is set, we must pass the argv except * -no option and invoke execvp() for no optimized loaddb */ if (No_optimization || envvar_get ("LOADDB_NOPT")) { char **tmp; char *lastslash, path[PATH_MAX]; int i = 1, j = 1; tmp = (char **) malloc (sizeof (char *) * (argc + 1)); tmp[0] = (char *) "loaddb"; while (j < argc) { if (!strcmp (argv[j], "-no")) j++; else tmp[i++] = argv[j++]; }; tmp[i] = 0; strcpy (path, argv[0]); lastslash = strrchr (path, (int) '/'); #if defined(WINDOWS) { char *p, exec_path[1024], cmd_line[1024 * 8]; int cp_len = 0; db_shutdown (); p = envvar_root (); if (p == NULL) { printf ("The `CUBRID' environment variable is not set.\n"); } else { sprintf (exec_path, "%s/migdb_o.exe", p); for (i = 0; tmp[i]; i++) { cp_len += sprintf (cmd_line + cp_len, "\"%s\" ", tmp[i]); } if (envvar_get ("FRONT_DEBUG") != NULL) { printf ("Executing:%s %s\n", exec_path, cmd_line); } run_proc (exec_path, cmd_line); } exit (0); } #else /* !WINDOWS */ if (lastslash != NULL) strcpy (lastslash + 1, "migdb_o"); else strcpy (path, "migdb_o"); if (execvp (path, tmp) == -1) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_NOPT_ERR)); exit (0); }; #endif /* WINDOWS */ } #endif /* !LDR_OLD_LOADDB */ #endif /* check if schema/index/object files exist */ ldr_check_file_name_and_line_no (); if (Schema_file[0] != 0) { schema_file = fopen (Schema_file, "r"); if (schema_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Schema_file); status = 2; goto error_return; } } if (Index_file[0] != 0) { index_file = fopen (Index_file, "r"); if (index_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Index_file); status = 2; goto error_return; } } if (Object_file[0] != 0) { object_file = fopen_ex (Object_file, "rb"); /* keep out ^Z */ if (object_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Object_file); status = 2; goto error_return; } } #if !defined (LDR_OLD_LOADDB) if (Ignore_class_file) { int retval; retval = get_ignore_class_list (Ignore_class_file); if (retval < 0) { status = 2; goto error_return; } } #endif /* Disallow syntax only and load only options together */ if (Load_only && Syntax_check) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INCOMPATIBLE_ARGS), "--" LOAD_LOAD_ONLY_L, "--" LOAD_CHECK_ONLY_L); status = 1; /* parsing error */ goto error_return; } if (Error_file[0] != 0) { if (Syntax_check) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INCOMPATIBLE_ARGS), "--" LOAD_ERROR_CONTROL_FILE_L, "--" LOAD_CHECK_ONLY_L); status = 1; /* parsing error */ goto error_return; } error_file = fopen_ex (Error_file, "rt"); if (error_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Error_file); status = 2; goto error_return; } er_filter_fileset (error_file); fclose (error_file); } /* check if no log option can be applied */ if (error || (Ignore_logging != 0 && locator_log_force_nologging () != NO_ERROR)) { /* couldn't log in */ print_log_msg (1, "%s\n", db_error_string (3)); status = 3; db_shutdown (); goto error_return; } /* change "print_key_value_on_unique_error" parameter */ sysprm_change_server_parameters ("print_key_value_on_unique_error=1"); /* if schema file is specified, do schema loading */ if (schema_file != NULL) { print_log_msg (1, "\nStart schema loading.\n"); /* * CUBRID 8.2 should be compatible with earlier versions of CUBRID. * Therefore, we do not perform user authentication when the loader * is executing by DBA group user. */ if (au_is_dba_group_member (Au_user)) { AU_DISABLE (au_save); } if (ldr_exec_query_from_file (Schema_file, schema_file, &schema_file_start_line, Periodic_commit) != 0) { print_log_msg (1, "\nError occurred during schema loading." "\nAborting current transaction..."); status = 3; db_shutdown (); print_log_msg (1, " done.\n\nRestart loaddb with '-%c %s:%d' option\n", LOAD_SCHEMA_FILE_S, Schema_file, schema_file_start_line); goto error_return; } if (au_is_dba_group_member (Au_user)) { AU_ENABLE (au_save); } print_log_msg (1, "Schema loading from %s finished.\n", Schema_file); /* update catalog statistics */ AU_DISABLE (au_save); sm_update_all_catalog_statistics (); AU_ENABLE (au_save); print_log_msg (1, "Statistics for Catalog classes have been updated.\n\n"); db_commit_transaction (); fclose (schema_file); schema_file = NULL; } /* if index file is specified, do index creation */ if (object_file != NULL) { #if defined (SA_MODE) locator_Dont_check_foreign_key = true; #endif print_log_msg (1, "\nStart object loading.\n"); ldr_init (Verbose); /* set the flag to indicate what type of interrupts to raise * If logging has been disabled set commit flag. * If logging is enabled set abort flag. */ if (Ignore_logging) Interrupt_type = LDR_STOP_AND_COMMIT_INTERRUPT; else Interrupt_type = LDR_STOP_AND_ABORT_INTERRUPT; if (Periodic_commit) { /* register the post commit function */ #if defined(LDR_OLD_LOADDB) ldr_register_post_commit_handler (&loaddb_report_num_of_commits); #else /* !LDR_OLD_LOADDB */ ldr_register_post_commit_handler (&loaddb_report_num_of_commits, NULL); #endif /* LDR_OLD_LOADDB */ } /* Check if we need to perform syntax checking. */ if (!Load_only) { print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_CHECKING)); do_loader_parse (object_file); #if defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults); #else /* !LDR_OLD_LOADDB */ ldr_stats (&errors, &objects, &defaults, &lastcommit); #endif /* LDR_OLD_LOADDB */ } else errors = 0; if (errors) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_ERROR_COUNT), errors); else if (!Syntax_check) { /* now do it for real if there were no errors and we aren't doing a simple syntax check */ ldr_start (Periodic_commit); fclose (object_file); object_file = fopen_ex (Object_file, "rb"); /* keep out ^Z */ if (object_file != NULL) { print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INSERTING)); /* make sure signals are caught */ util_arm_signal_handlers (signal_handler, signal_handler); /* register function to call and jmp environment to longjmp to * after aborting or committing. */ ldr_register_post_interrupt_handler (&loaddb_get_num_of_inserted_objects, &loaddb_jmp_buf); if (setjmp (loaddb_jmp_buf) != 0) { /* We have had an interrupt, the transaction should have * been already been aborted or committed by the loader. * If Total_objects_loaded is -1 an error occurred during * rollback or commit. */ if (Total_objects_loaded != -1) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_OBJECT_COUNT), Total_objects_loaded); #if !defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults, &lastcommit); if (lastcommit > 0) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_LAST_COMMITTED_LINE), lastcommit); #endif /* !LDR_OLD_LOADDB */ interrupted = true; } else { do_loader_parse (object_file); #if defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults); #else /* !LDR_OLD_LOADDB */ ldr_stats (&errors, &objects, &defaults, &lastcommit); #endif /* LDR_OLD_LOADDB */ if (errors) { #if defined(LDR_OLD_LOADDB) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_ERROR_COUNT), errors); #else /* !LDR_OLD_LOADDB */ if (lastcommit > 0) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_LAST_COMMITTED_LINE), lastcommit); #endif /* LDR_OLD_LOADDB */ /* * don't allow the transaction to be committed at * this point, note that if we ever move to a scheme * where we write directly to the heap without the * transaction context, we will have to unwind the * changes made if errors are detected ! */ db_abort_transaction (); } else { if (objects) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_OBJECT_COUNT), objects); if (defaults) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_DEFAULT_COUNT), defaults); print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_COMMITTING)); /* commit the transaction and then update statistics */ if (!db_commit_transaction ()) { if (!Disable_statistics) { if (Verbose) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATING_STATISTICS)); if (!ldr_update_statistics ()) { /* * would it be faster to update statistics * before the first commit and just have a * single commit ? */ print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_COMMITTING)); (void) db_commit_transaction (); } } } } } } } ldr_final (); if (object_file != NULL) { fclose (object_file); object_file = NULL; } } /* create index */ if (!interrupted && index_file != NULL) { print_log_msg (1, "\nStart index loading.\n"); if (ldr_exec_query_from_file (Index_file, index_file, &index_file_start_line, Periodic_commit) != 0) { print_log_msg (1, "\nError occurred during index loading." "\nAborting current transaction..."); status = 3; db_shutdown (); print_log_msg (1, " done.\n\nRestart loaddb with '-%c %s:%d' option\n", LOAD_INDEX_FILE_S, Index_file, index_file_start_line); goto error_return; } /* update catalog statistics */ AU_DISABLE (au_save); sm_update_catalog_statistics (CT_INDEX_NAME); sm_update_catalog_statistics (CT_INDEXKEY_NAME); AU_ENABLE (au_save); print_log_msg (1, "Index loading from %s finished.\n", Index_file); db_commit_transaction (); } print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_CLOSING)); (void) db_shutdown (); #if !defined (LDR_OLD_LOADDB) free_ignoreclasslist (); #endif return (status); error_return: if (schema_file != NULL) fclose (schema_file); if (object_file != NULL) fclose (object_file); if (index_file != NULL) fclose (index_file); #if !defined (LDR_OLD_LOADDB) free_ignoreclasslist (); #endif return status; }
static void run_cmds(int n_cmds, Cmd *cmds) { for (int i = 0; i < n_cmds; ++i) { if (! cmds[i].configuring) cmds[i].pid = run_proc(cmds[i].args); } }
/*Method to run a first come first serve scheduling routine*/ int runFCFS(Processes *proc, int time_interval) { if(proc == NULL) { DEBUGPRINTF("ERROR: No process list passed to FCFS\n"); exit(1); } RunningProcesses * rp = createRunningProcesses(); addProc(rp,0); int runTime = time_interval; Node * temp = NULL; //decalre phase int block = 0; int arrival = 0; int proc_arrival = 0; int current_time = 0; int finish = 0; int runProcReturn = 0; //initilize variables for printing int startArray[10000]; int endArray[10000]; int runArray[10000]; int blocksArray[10000]; double upArray[10000]; int totalIdle = 0; int j = 0; for(j = 0; j <10000; j++) { startArray[j] = 0; endArray[j]= 0; runArray[j]=0; blocksArray[j]=0; upArray[j]=0; } while(rp->size != 0)//while there are still jobs to be run { //reset variables block = 0; arrival = 0; proc_arrival = 0; finish = 0; runProcReturn = 0; // temp = rp->head; runTime = time_interval; //find the shortest blocktime to run up too while (temp != NULL && temp->isBlocked != 0)//0 is not blocked 1 is blocked { if (temp->remainingBlockTime < runTime) { runTime = temp->remainingBlockTime; } temp = temp->next; } //NOTE //If TEMP==NULL then we can do run_noProc_check else if temp is a proc then do run_proc if (temp != NULL)//a process was found that could be run { runProcReturn = run_proc(proc, temp->procID, runTime, &block, &finish, current_time, &arrival, &proc_arrival);//run the process } else//there are no processes that can be run { runProcReturn = proc_norun_check_arrival(proc, time_interval, current_time, &arrival, &proc_arrival); totalIdle += runProcReturn; } if (runProcReturn != -1) { current_time += runProcReturn;//increment current time } //arrival found if (arrival == 1) { addProc(rp,proc_arrival); startArray[proc_arrival] = current_time; } //block found if(block == 1) { temp->isBlocked = 1; blocksArray[temp->procID]++; } //finish process if (finish == 1) { endArray[temp->procID] = current_time; upArray[temp->procID] = runArray[temp->procID] / endArray[temp->procID]; runArray[temp->procID] = endArray[temp->procID] - startArray[temp->procID]; removeProc(rp,temp->procID); } if (rp->size != 0) // set temp back to the head { temp = rp->head; } //increment all times while (temp != NULL && temp->isBlocked != 0 && runProcReturn != -1)//0 is not blocked 1 is blocked { if (temp->isBlocked == 1) { temp->remainingBlockTime -= runProcReturn; } if(temp->remainingBlockTime <= 0)//unblock processthat have done there time in the slammer { temp->isBlocked = 0; temp->remainingBlockTime = 200; } temp = temp->next; } } // Fill in with your stats! int i = 0; printf("********** SUMMARY ***********\n"); printf("\tStart\tend\trun\tblocks\tutil percent\n"); int sumRun = 0; for(i=0;endArray[i] != 0;i++) { upArray[i] = (double)runArray[i] / (double) endArray[i]; printf("PID%d:\t%d\t%d\t%d\t%d\t%1.3f\n",i,startArray[i],endArray[i],runArray[i],blocksArray[i],upArray[i]); sumRun += runArray[i]; } printf("Mean Time to Finish:\t%d\n",(sumRun / i)); printf("Total idle time:\t%d\n",totalIdle); return 0; }
int main(int argc, char* argv[]) { int opt; int f = DEFAULT_F; int m = DEFAULT_M; int k0 = DEFAULT_K0; int k1 = DEFAULT_K1; int k2 = DEFAULT_K2; int d = DEFAULT_D; /* Read arguments */ while(-1 != (opt = getopt(argc, argv, "d:i:j:k:l:f:m:h"))) { switch(opt) { case 'd': d = atoi(optarg); break; case 'j': k0 = atoi(optarg); break; case 'k': k1 = atoi(optarg); break; case 'l': k2 = atoi(optarg); break; case 'm': m = atoi(optarg); break; case 'f': f = atoi(optarg); break; case 'i': inFile = fopen(optarg, "r"); if (inFile == NULL) { fprintf(stderr, "Failed to open %s for reading\n", optarg); print_help_and_exit(); } break; case 'h': /* Fall through */ default: print_help_and_exit(); break; } } dout("Processor Settings\n"); dout("D: %i\n", d); dout("k0: %i\n", k0); dout("k1: %i\n", k1); dout("k2: %i\n", k2); dout("F: %i\n", f); dout("M: %i\n", m); dout("\n"); /* Setup the processor */ setup_proc(inFile, d, k0, k1, k2, f, m); /* Setup statistics */ proc_stats_t stats; memset(&stats, 0, sizeof(proc_stats_t)); /* Run the processor */ run_proc(&stats); /* Finalize stats */ complete_proc(&stats); print_statistics(&stats); return 0; }
int main(int argc, char *argv[]){ //Init queues q_dispatch = (queue*)malloc(sizeof(queue*)); q_dispatch->head=NULL; q_dispatch->tail=NULL; q_real = (queue*)malloc(sizeof(queue*)); q_real->head=NULL; q_real->tail=NULL; q_1 = (queue*)malloc(sizeof(queue*)); q_1->head=NULL; q_1->tail=NULL; q_2 = (queue*)malloc(sizeof(queue*)); q_2->head=NULL; q_2->tail=NULL; q_3 = (queue*)malloc(sizeof(queue*)); q_3->head=NULL; q_3->tail=NULL; //Init resources for(int i=0;i<PRINTERS;i++){res_avail.printers[i]=0;} for(int i=0;i<SCANNERS;i++){res_avail.scanners[i]=0;} for(int i=0;i<MODEMS;i++){res_avail.modems[i]=0;} for(int i=0;i<DRIVES;i++){res_avail.drives[i]=0;} for(int i=0;i<MEMORY;i++){res_avail.memory[i]=0;} // Load the dispatchlist adds to queue as well load_dispatch(argv[1]); int tick =0; //Start dispatching while(true){ //check dispatch list for processes that have arrived node* dispatch_node = q_dispatch->head; while(dispatch_node){ if(dispatch_node->process.arrival_time==tick){ //Push process to appropriate queue switch(dispatch_node->process.priority){ case 0: push(q_real,dispatch_node->process); break; case 1: push(q_1,dispatch_node->process); break; case 2: push(q_2,dispatch_node->process); break; case 3: push(q_3,dispatch_node->process); break; } } dispatch_node=dispatch_node->next; } //Run processes proc* get_proc; bool find_proc = true; int count; //Real Time Queue count = q_size(q_real); //loop through queue if there is something in queue and no job has been found while(find_proc&&count>0){ get_proc = pop(q_real); //check if process can be allocated if(alloc_resources(&res_avail,get_proc)){ //run run_proc(get_proc); find_proc=false; }else{ push(q_real,*get_proc); count--; } } //1st Queue count = q_size(q_1); //loop through queue if there is something in queue and no job has been found while(find_proc&&count>1){ get_proc = pop(q_1); //Check if process can be allocated if(alloc_resources(&res_avail,get_proc)){ //run if not completed during run push to next queue if(run_proc(get_proc)) push(q_2,*get_proc); find_proc=false; }else{ //if resources not available push back onto queue push(q_1,*get_proc); count--; } } //2nd Queue count = q_size(q_2); //loop through queue if there is something in queue and no job has been found while(find_proc&&count>0){ get_proc = pop(q_2); //if process is a new process if(!get_proc->suspended){ //check if it can be allocated if(alloc_resources(&res_avail,get_proc)){ //run if not completed during run push to next queue if(run_proc(get_proc)) push(q_3,*get_proc); find_proc=false; }else{ //if resources not available push back onto queue push(q_2,*get_proc); count--; } }else{ //if processes has already been allocated just run it some more if(run_proc(get_proc)) push(q_3,*get_proc); find_proc=false; } } //3rd Qeue count = q_size(q_3); while(find_proc&&count>0){ get_proc = pop(q_3); if(!get_proc->suspended){ if(alloc_resources(&res_avail,get_proc)){ if(run_proc(get_proc)) push(q_3,*get_proc); find_proc=false; }else{ push(q_3,*get_proc); count--; } }else{ if(run_proc(get_proc)) push(q_3,*get_proc); find_proc=false; } } //if no process was able to be run either system is hung or there are no jobs left if(find_proc){ printf("TERMINATING: Could not find anymore processes\n"); break; } //increase tick count on dispatcher tick++; } return EXIT_SUCCESS; }