int main() { init_shell(); while(1) { char prompt[256]; if(!readcmdline(promptmsg(prompt, 256))) { if (feof(stdin)) { /* End of file (ctrl-d) */ fflush(stdout); printf("\n"); exit(EXIT_SUCCESS); } continue; /* NOOP; user entered return or spaces with return */ } job_t* j; for (j = first_job; j; j = j->next) { /*Execute the new job (initialized with pgID = -1)*/ if (j->pgid == -1) { execute_job(j); } } } }
int main() { init_shell(); job_array = (pid_t *) malloc(20*sizeof(pid_t)); while(1) { if(!readcmdline(promptmsg())) { if (feof(stdin)) { /* End of file (ctrl-d) */ fflush(stdout); printf("\n"); exit(EXIT_SUCCESS); } continue; /* NOOP; user entered return or spaces with return */ } /* Only for debugging purposes and to show parser output */ //print_job(); job_t * next_job = first_job; while(next_job){ if(next_job->pgid ==-1){ int lowest = find_lowest_index(); //printf("%s %d\n","Lowest index: ", lowest); if(lowest != -1){ bool bg = next_job->bg; process_t * p = next_job->first_process; char* cmd = p->argv[0]; if(strcmp (cmd,"cd") == 0){ //printf("%s\n", "found cd"); } else if (strcmp (cmd, "jobs") == 0) { list_jobs(next_job, 0); job_t *tmp = next_job; if (next_job->next) next_job=next_job->next; remove_and_free(tmp); //why are we remove and freeing a built in command } else if (strcmp(cmd, "fg") == 0) { } else if (strcmp(cmd, "bg") == 0) { } else { /*If not built-in*/ spawn_job(next_job, !bg); next_job = next_job->next; } break; } } else next_job = next_job->next; } /* You need to loop through jobs list since a command line can contain ;*/ /* Check for built-in commands */ /* If not built-in */ /* If job j runs in foreground */ /* spawn_job(j,true) */ /* else */ /* spawn_job(j,false) */ } }
int main() { init_dsh(); DEBUG("Successfully initialized\n"); while(1) { job_t *j = NULL; if(!(j = readcmdline(promptmsg(getpid())))) { if (feof(stdin)) { /* End of file (ctrl-d) */ fflush(stdout); printf("\n"); exit(EXIT_SUCCESS); } continue; /* NOOP; user entered return or spaces with return */ } /* Only for debugging purposes to show parser output; turn off in the * final code */ // if(PRINT_INFO) print_job(j); /* Your code goes here */ /* You need to loop through jobs list since a command line can contain ;*/ /* Check for built-in commands */ /* If not built-in */ /* If job j runs in foreground */ /* spawn_job(j,true) */ /* else */ /* spawn_job(j,false) */ while (j != NULL) { // if EOF builtincmd of quit //active jobs is last job? // if not a command at all ? bool is_built_in_cmd = builtin_cmd(j, (j->first_process)->argc, (j->first_process)->argv); if(!is_built_in_cmd) { if(j->bg == true) { spawn_job(j, false); } else { spawn_job(j, true); } if(active_jobs_head == NULL) { active_jobs_head = j; } else { job_t *lastJob = find_last_job(active_jobs_head); lastJob->next = j; j->next = NULL; } } j = j->next; } } }