int main (int argc, char *argv[]) { passenger **arr = input (argv[1]); int nr_passengers; FILE *fp = fopen (argv[1], "r"); fscanf (fp, "%d", &nr_passengers); fclose (fp); pid_t bag_c, immig; // bag_c = fork(); int i = 0; while (i < nr_passengers) { FILE *ptr = fopen ("pointer.txt","w"); fprintf (ptr, "%p", arr[i]); fflush (ptr); fclose (ptr); if (i == 0) { bag_c = fork(); if (!bag_c) { baggage_counter (); } else { kill (getpid(), SIGSTOP); i++; ptr = fopen ("pointer.txt","w"); fprintf (ptr, "%p", arr[i]); fflush (ptr); fclose (ptr); kill (bag_c, SIGCONT); immig = fork(); if (!immig) immigration (); else kill (getpid(), SIGSTOP); } } else { // kill (bag_c, SIGCONT); i++; usleep (100); kill (bag_c, SIGCONT); usleep (100); kill (immig, SIGCONT); kill (getpid(), SIGSTOP); } } // baggage_counter (0); return 0; }
void Solver::run( const Instance & instance, const TerminationCondition & termination, int population_size ) { // generate random population for(int i = 0; i < population_size; i++){ Individual * next = new Individual(instance.num_words()); state.inc_processed(); next->randomize(); next->set_cost(instance.evaluate(next)); state.population().add(next); } // evaluate individuals, sort them etc. update_population(instance); while( !termination(state) ){ // select parents std::vector<const Individual *> parents = parent_selector(state); // crossover std::vector<Individual *> children = crossover_strategy(state, parents); // mutation mutation_strategy(state, children); // evaluate children for(unsigned int i = 0; i < children.size(); i++){ int c = instance.evaluate(children[i]); state.inc_processed(); children[i]->set_cost(c); } local_search(state, children); // replacement replacement_strategy(state, children); update_population(instance); immigration(state, instance); update_population(instance); // one more iteration... state.inc_iteration(); printf("current iteration : %5d best: %d diversity : %lf processed : %llu \n", state.iteration(), state.population().best(), state.population().diversity(), state.processed()); fflush(stdout); save_iteration_info(); } }
int main() { takeInputs(); FILE *f = fopen("Ids.txt","w"); printf("I am the AIRPORT PROCESS. PID: %d ; Parent ID : %d\n",getpid(),getppid()); boardPid = fork(); if(boardPid == 0) { board_pass(user); exit(4); } waloPid = fork(); if(waloPid == 0) { wait_lounge(user); exit(4); } secPid = fork(); if(secPid == 0) { security(user); exit(3); } immPid = fork(); if(immPid == 0) { immigration(user); exit(2); } bagPid = fork(); if(bagPid == 0) { baggage(user); exit(1); } fprintf(f,"%d ",bagPid); fprintf(f,"%d ",immPid); fprintf(f,"%d ",secPid); fprintf(f,"%d ",waloPid); fprintf(f,"%d ",boardPid); fclose(f); //Main function block int y,i,j; for(y=0;y<allowed;y++) { printf("\nMain User number : %d => \n",y); sleep(1); kill(bagPid,SIGCONT); waitpid(bagPid,&status,WUNTRACED); kill(immPid,SIGCONT); } kill(getpid(),SIGSTOP); int wait_count; f = fopen("./board_pass/wait_count.txt","r"); fscanf(f,"%d",&wait_count); fclose(f); printf("\nAIRPORT SPEAKING ==> Total number of passengers arrived at airport : %d\n",allowed); printf("\nAIRPORT SPEAKING ==> Total number of passengers boarded : %d\n",allowed-wait_count); printf("\nAIRPORT SPEAKING ==> Flight number %d ready for departure with %d passengers\n",getpid(),allowed-wait_count); while(wait(NULL)!= -1); return 0; }