setup::setup(QWidget *parent) : QMainWindow(parent), ui(new Ui::setup) { ui->setupUi(this); setWindowIcon(QIcon(":/icons/Bambilo")); v=new MainWindow(); prc=new QProcess(); //--------- /* ui->lineEdit->setVisible(false); ui->lineEdit_2->setVisible(false); ui->label->setVisible(false); ui->label_2->setVisible(false);*/ //-------- QSettings checktool("Tools","tool"); procCOCOS_CONSOLE=checktool.value("setCOCOS_CONSOLE").toString(); procCOCOS_TEMPLATES=checktool.value("setCOCOS_TEMPLATES").toString(); procSDK=checktool.value("setSDK").toString(); procNDK=checktool.value("setNDK").toString(); procANT=checktool.value("setANT").toString(); procCOCOS=checktool.value("setCOCOS").toString(); string ant=procANT.toStdString().erase(0,9); string ndk=procNDK.toStdString().erase(0,9); string sdk=procSDK.toStdString().erase(0,17); string cocostemplates=procCOCOS_TEMPLATES.toStdString().erase(0,21); string cocosconsole=procCOCOS_CONSOLE.toStdString().erase(0,19); // ------------------------------------------------------ process settings QProcessEnvironment env=QProcessEnvironment::systemEnvironment(); env.insert("JAVA_HOME","/usr"); env.insert("PATH",env.value("PATH")+":$JAVA_HOME:$PATH"); env.insert("COCOS_CONSOLE_ROOT",QString::fromStdString(cocosconsole)); env.insert("PATH",env.value("PATH")+":$COCOS_CONSOLE_ROOT:$PATH"); env.insert("COCOS_TEMPLATES_ROOT",QString::fromStdString(cocostemplates)); env.insert("PATH",env.value("PATH")+":$COCOS_TEMPLATES_ROOT:$PATH"); env.insert("ANDROID_SDK_ROOT",QString::fromStdString(sdk)); env.insert("PATH",env.value("PATH")+":$ANDROID_SDK_ROOT:$PATH"); env.insert("PATH",env.value("PATH")+":$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH"); env.insert("NDK_ROOT",QString::fromStdString(ndk)); env.insert("PATH",env.value("PATH")+":$NDK_ROOT:$PATH"); env.insert("ANT_ROOT",QString::fromStdString(ant)); env.insert("PATH",env.value("PATH")+":$ANT_ROOT:$PATH"); prc->setWorkingDirectory(procCOCOS); prc->setProcessEnvironment(env); connect(prc,SIGNAL(readyReadStandardOutput()),this,SLOT(yazdir())); connect(prc,SIGNAL(readChannelFinished()),this,SLOT(readProcess())); }
// simple method to setup the intial number of processes void setUpProcesses() { int status; while ((status=readProcess(&processes[numberOfProcesses])) && numberOfProcesses <= MAX_PROCESSES) { if( status==1 ) { numberOfProcesses++; } } }
int main() { readProcess(); sort(); sjf(); print(); return 0; }
void RunDialog::runFinished(int exitCode, QProcess::ExitStatus exitStatus) { finished_ = true; readProcess(); // Check exit conditions. if (aborted_) runAborted(); else if (exitStatus == QProcess::CrashExit) runCrashed(); else if (exitCode != 0) runFailed(); else runCompleted(); // Set the button status. cancelButton_->setEnabled(false); closeButton_->setEnabled(true); closeButton_->setFocus(); if (autoClose_->isChecked() && autoClose_->isEnabled() && !(failed_ || aborted_)) accept(); }
int main(int argc, char **argv) { if (argc < 3) { fprintf(stderr, "Please enter a time quantums . . . . \n"); exit(1); } time_slice = atoi(argv[1]); time_slice_1 = atoi(argv[2]); if (time_slice <= 0 || time_slice_1 <= 0) { fprintf(stderr, "Error! program usage rr < positive time quantum> < data file . . .\n"); exit(1); } init_(); clock_t ticks; time_t start_time, end_time; time(&start_time); int i; int status = 0; log_file = fopen("log_file.txt", "w+"); if (log_file == NULL) { fprintf(stderr, "LOG FILE CANNOT BE OPEN\n"); } //initialize cpu's for (i = 0; i < NUMBER_OF_PROCESSORS; i++) { CPU[i] = NULL; } initializeProcessQueue(&readyQueue); initializeProcessQueue(&waitingQueue); initializeProcessQueue(&level_one); initializeProcessQueue(&second_level); //initializeProcessQueue(&promoted); // read in process and initialize process values while ((status = (readProcess(&processes[number_of_processes])))) { if (status == 1) { number_of_processes++; } } if (number_of_processes > MAX_PROCESSES) { return -2; } if (number_of_processes == 0) { return -1; } int remaining_process = 0; //sort process by their arrival times qsort(processes, number_of_processes, sizeof (process), compareByArrival); // main execution loop while (TRUE) { ticks = clock(); waiting_to_ready(); incoming_process_init(); running_process_to_waiting(); most_ready_running_in_cpu(); refresh_processes(); increase_io_work(); increase_cpu_work(); cpu_utilized_time += runningProcesses(); remaining_process = ex(); // break when there are no more running or incoming processes, and the waiting queue is empty if (remaining_process == 0 && runningProcesses() == 0 && waitingQueue.size == 0) { break; } simulation_time++; } int total_waiting_time = 0; int turn_around_time = 0; for (i = 0; i < number_of_processes; i++) { turn_around_time += processes[i].endTime - processes[i].arrivalTime; total_waiting_time += processes[i].waitingTime; } printf(">>>>>>>>>>>>> FBQ with Q1 :%d\tQ2 :%d <<<<<<<<<<<<<<<\n", time_slice, time_slice_1); printf("********************************************************************\n"); printf("Average Waiting Time\t\t\t:%.2f\n", total_waiting_time / (double) number_of_processes); printf("Average Turn Around Time\t\t:%.2f\n", turn_around_time / (double) number_of_processes); printf("Time all for all CPU processes\t\t:%d\n", simulation_time); printf("CPU Utilization Time\t\t\t:%.2f%c\n", (double) (cpu_utilized_time * 100.0) / (double) (simulation_time), (int) 37); printf("Total Number of Context Switches\t:%d\n", context_switches); printf("Last Process to finish "); for (i = 0; i < number_of_processes; i++) { if (processes[i].endTime == simulation_time) { printf("PID\t\t:%d\n", processes[i].pid); } } printf("********************************************************************\n"); time(&end_time); double prg_time = (end_time - start_time) * 0.001; double cpu_time = (double) ticks / CLOCKS_PER_SEC; fprintf(log_file, "Program Time\t:%.2fsecs\n", prg_time); fprintf(log_file, "CPU Time\t:%.2fsecs\n", cpu_time); fclose(log_file); return 0; }
int main(int argc, char **argv) { /* initialzie some global and local variables */ int status = 0; int lastPid, j; int totalUtilized = 0, totalWaiting = 0, totalTurnAround = 0; double avgWaiting, avgTurnAround, avgUtil; clockTime = 0; processIndex = 0; tempArrayIndex = 0; timeSlice = atoi(argv[1]); /* initialize the CPUs, set all cpus to idle status and no process is assigned to any one of them */ for(j = 0; j < NUMBER_OF_PROCESSORS; j++) { cpus[j] = NULL; } /* initialize process queue to store processes */ initializeProcessQueue(&ready_queue); initializeProcessQueue(&device_queue); /* read from the file and sort them in order for later on enqueue */ while((status = readProcess(&processes[numberOfProcesses]))) { if(status == 1) { numberOfProcesses++; } if (numberOfProcesses > MAX_PROCESSES || numberOfProcesses == 0){ error_invalid_number_of_processes(numberOfProcesses); } } qsort(processes, numberOfProcesses, sizeof(process), compareByArrival); /** the idea is: as we increase the clockTime from 0 to a very large number until some conditions, * at every time spot, we need to allocate cpu to a process, enqueue process to device_queque or * enqueue process back to ready_queue. */ while(1) { /* some actions at current time spot */ /** first we want to call nextUnitProcess() to get a temporary array of process(es) which are * arrange by arrival time. * second do all the checks for all queue and process to determin where are they going to * and what actions they have to do. */ nextUnitProcess(); // at each time spot, add matched process to be run to tempArray cpuOut(); // initially not executed since no cpus is running. ioToReadyQ(); // to check io queue if some processes should go back to ready_queue. readyQtoCPU(); // equeue all processes from sorted tempArray into ready_queue and allocate cpus for them. /* now we have to make progress, which is going to next unit of time */ nextUnitTime(); /* for each clockTime spot, we sum up the total */ totalUtilized += isAllIdle(); /** now it is time to do some termination check * exit the progress-making when: * 1: all cpus are idle status * 2: no next unit of processes to be added to tempArray * 3: the waiting queue is empty */ if((isAllIdle() == 0) && ((numberOfProcesses - processIndex) == 0) && (device_queue.size == 0) ) { break; } /* add one more unit time to next step */ clockTime++; } /* calculation and display result */ for(j = 0; j < numberOfProcesses; j++) { totalWaiting += processes[j].waitingTime; totalTurnAround += (processes[j].endTime - processes[j].arrivalTime); if(processes[j].endTime == clockTime) { lastPid = processes[j].pid; } } avgWaiting = totalWaiting / (double)numberOfProcesses; avgTurnAround = totalTurnAround / (double)numberOfProcesses; avgUtil = totalUtilized / (double)clockTime; printf("The average waiting time is: %.2f\n" "The average turnaround time is: %.2f\n" "The CPUs finished at: %d\n" "The average cpu utilization is: %.2f%%\n" "Total context switches: %d\n" "The last process is: %d\n", avgWaiting, avgTurnAround, clockTime, avgUtil*100, totalCW, lastPid); }
int main() { clock_t ticks; time_t start_time, end_time; time(&start_time); int i; int status = 0; log_file = fopen("log_file.txt", "w+"); if (log_file == NULL) { fprintf(stderr, "LOG FILE CANNOT BE OPEN\n"); } // initialize cpus for (i = 0; i < NUMBER_OF_PROCESSORS; i++) { CPU[i] = NULL; } init_(); initializeProcessQueue(&readyQueue); initializeProcessQueue(&waitingQueue); // read in process and initialize process values while ((status = (readProcess(&processes[number_of_processes])))) { if (status == 1) { number_of_processes++; } if (number_of_processes > MAX_PROCESSES || number_of_processes == 0) { break; } } //sort process by their arrival times qsort(processes, number_of_processes, sizeof (process), compareByArrival); // main execution loop while (TRUE) { ticks = clock(); incoming_process_init(); running_process_to_waiting(); most_ready_running_in_cpu(); waiting_to_ready(); refresh_processes(); cpu_utilized_time += runningProcesses(); simulation_time++; // break when there are no more running or incoming processes, and the waiting queue is empty if (runningProcesses() == 0 && (number_of_processes - nextProcess) == 0 && waitingQueue.size == 0) { break; } } // calculations based on CPU simulations int total_waiting_time = 0; int turn_around_time = 0; for (i = 0; i < number_of_processes; i++) { turn_around_time += processes[i].endTime - processes[i].arrivalTime; total_waiting_time += processes[i].waitingTime; } printf("********************************************************************\n"); printf("Average Waiting Time\t\t\t:%.2f\n", total_waiting_time / (double) number_of_processes); printf("Average Turn Around Time\t\t:%.2f\n", turn_around_time / (double) number_of_processes); printf("Time all for all CPU processes\t\t:%d\n", simulation_time); printf("CPU Utilization Time\t\t\t:%.2f%c\n", (double) (cpu_utilized_time * 100.0) / (double) (simulation_time), (int) 37); printf("Total Number of Context Switches\t:%d\n", context_switches); printf("Last Process to finish "); for (i = 0; i < number_of_processes; i++) { if (processes[i].endTime == last_process_end_time) { printf("PID\t\t:%d\n", processes[i].pid); } } //printf("%d\n" , processes[number_of_processes].pid); printf("********************************************************************\n"); time(&end_time); double prg_time = (end_time - start_time) * 0.001; double cpu_time = (double) ticks / CLOCKS_PER_SEC; fprintf(log_file, "Program Time\t:%.2fsecs\n", prg_time); fprintf(log_file, "CPU Time\t:%.2fsecs\n", cpu_time); fclose(log_file); return 0; }
int main(void) { int sumOfTurnaroundTimes = 0; int doneReading = 0; int i; /* read in all process data and populate processes array with the results */ initializeGlobals(); while (doneReading=readProcess(&processes[numberOfProcesses])) { if(doneReading==1) numberOfProcesses ++; if(numberOfProcesses > MAX_PROCESSES) break; } /* handle invalid number of processes in input */ if (numberOfProcesses == 0) { fprintf(stderr, "Error: no processes specified in input.\n"); return -1; } else if (numberOfProcesses > MAX_PROCESSES) { fprintf(stderr, "Error: too many processes specified in input; " "they cannot number more than %d.\n", MAX_PROCESSES); return -1; } /* sort the processes array ascending by arrival time */ qsort(processes, numberOfProcesses, sizeof(process), compareByArrival); /* run the simulation */ while (1) { moveIncomingProcesses(); /* admit any newly arriving processes */ moveRunningProcesses(); /* move procs that shouldn't be running */ moveWaitingProcesses(); /* move procs finished waiting to ready-Q */ moveReadyProcesses(); /* move ready procs into any free cpu slots */ updateWaitingProcesses(); /* update burst progress for waiting procs */ updateReadyProcesses(); /* update waiting time for ready procs */ updateRunningProcesses(); /* update burst progress for running procs */ cpuTimeUtilized += runningProcesses(); /* terminate simulation when: - no processes are running - no more processes await entry into the system - there are no waiting processes */ if (runningProcesses() == 0 && incomingProcesses() == 0 && waitingQueue.size == 0) break; simulationTime++; } for (i = 0; i < numberOfProcesses; i++) printf("Process #%d: Arrival=%d, Start=%d, End=%d, Waiting=%d\n", processes[i].pid, processes[i].arrivalTime, processes[i].startTime, processes[i].endTime, processes[i].waitingTime); /* compute and output performance metrics */ for (i=0;i<numberOfProcesses;i++) { sumOfTurnaroundTimes += processes[i].endTime - processes[i].arrivalTime; totalWaitingTime += processes[i].waitingTime; } printf("totalWaitingTime = %d\nnumberOfProcesses = %d\n", totalWaitingTime, numberOfProcesses); printf("Average waiting time : %.2f units\n" "Average turnaround time : %.2f units\n" "Time all processes finished : %d\n" "Average CPU utilization : %.1f%%\n" "Number of context switches : %d\n", totalWaitingTime / (double) numberOfProcesses, sumOfTurnaroundTimes / (double) numberOfProcesses, simulationTime, 100.0 * cpuTimeUtilized / simulationTime, totalContextSwitches); printf("PID(s) of last process(es) to finish :"); for (i=0;i<numberOfProcesses;i++) { if (processes[i].endTime == simulationTime) { printf(" %d", processes[i].pid); } } printf("\n"); return 0; }