/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { // printf("fK:%s : %s \n",argv[0],argv[2]); if(strcmp(argv[0], "quit")==0) { exit(0); // exits the shell return 1; } else if(strcmp(argv[0], "bg")==0) { do_bgfg(argv); return 1; } else if(strcmp(argv[0], "fg")==0) { do_bgfg(argv); return 1; } else if(strcmp(argv[0], "jobs")==0) { listjobs(jobs); return 1; } else{ return 0; } return 0; // never makes it here }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. * the builtin_cmd include quit, jobs, bg <job>, and fg <job> */ int builtin_cmd(char **argv) { //quit if( !strcmp(argv[0], "quit")){ exit(0); } //jobs else if (!strcmp(argv[0], "jobs")){ listjobs(jobs); return 1; } //bg else if(!strcmp(argv[0], "bg")){ do_bgfg(argv); return 1; } //fg else if(!strcmp(argv[0], "fg")){ do_bgfg(argv); return 1; } else{ return 0; /* not a builtin command */ } }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { //if(verbose) //printf("%s\n",argv[0]); /*builtin cmd quit*/ if(!(strcmp(argv[0],"quit"))){ exit(0); } /*builtin cmd jobs prints the currently running and stopped jobs*/ else if(!(strcmp(argv[0],"jobs"))){ listjobs(jobs); return 1; } /*builtin cmd fg for converting a process to foreground*/ else if(!(strcmp(argv[0],"fg"))){ do_bgfg(argv); return 1; } /*builtin cmd bg for converting a process to background*/ else if(!(strcmp(argv[0],"bg"))){ do_bgfg(argv); return 1; } /* not a builtin command */ else { return 0; } }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (strcmp(argv[0], "quit")==0) exit(0); else if (strcmp(argv[0], "fg")==0) do_bgfg(argv); else if (strcmp(argv[0], "bg")==0) do_bgfg(argv); else if (strcmp(argv[0], "jobs")==0) listjobs(jobs); else return 0; /* not a builtin command */ return 1; }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(!strcmp(argv[0],"quit")){ exit(0); }else if(!strcmp(argv[0],"jobs")){ listjobs(jobs); return 1; }else if(!strcmp(argv[0],"bg")){ do_bgfg(argv); return 2; }else if(!strcmp(argv[0],"fg")){ do_bgfg(argv); return 3; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (!strcmp(argv[0], "quit")) { exit(0); } if (!strcmp(argv[0], "jobs")) { listjobs(jobs); return 1; } if ((!strcmp(argv[0], "bg") || !strcmp(argv[0], "fg")) && (argv[1] != NULL)) { do_bgfg(argv); return 1; } if (!strcmp(argv[0], "kill")) { pid_t pid = atoi(argv[1]); kill(-pid, SIGKILL); if (getjobpid(jobs, pid) != NULL) { if (waitpid(pid, NULL, 0) < 0) unix_error("kill child process error"); deletejob(jobs, pid); } return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { //list jobs for "jobs" command if(!strcmp(argv[0], "jobs")) { listjobs(jobs); return 1; } //calling do_bgfg if built-in commands are fg or bg else if(!strcmp(argv[0], "fg") || !strcmp(argv[0], "bg")) { do_bgfg(argv); return 1; } //exit shell if command is quit else if(!strcmp(argv[0], "quit")) { exit(0); } //run process in background if & is parsed as command else if(!strcmp(argv[0], "&")) { return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-int * command then execute it immediately. * quit, fg, bg, jobs */ int builtin_cmd(char **argv) { char *cmd = argv[0]; sigset_t mask, prev; /* Blocks all signals while determining * whether command is built in */ Sigfillset(&mask); Sigprocmask(SIG_BLOCK, &mask, &prev); if (!strcmp(cmd, "quit")) { Sigprocmask(SIG_SETMASK, &prev, NULL); exit(0); } if (!strcmp(cmd, "jobs")) { listjobs(jobs); Sigprocmask(SIG_SETMASK, &prev, NULL); return 1; } if (!strcmp(cmd, "bg") || !strcmp(cmd, "fg")) { Sigprocmask(SIG_SETMASK, &prev, NULL); do_bgfg(argv); return 1; } Sigprocmask(SIG_SETMASK, &prev, NULL); return 0; }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { int r=0; char* p; int jobid; if(strcmp(argv[0],"quit")==0) { r++; exit(0); } else if(strcmp(argv[0],"jobs")==0) { r++; listjobs(jobs); } else if((strcmp(argv[0],"bg")==0)||(strcmp(argv[0],"fg")==0)) { r++; do_bgfg(argv); } else if(strcmp(argv[0],"kill")==0) { r++; p = strstr(argv[1],"%"); p++; jobid=atoi(p); //Since jobid is specified as %5 for job 5 we get 5 from argv[1]. jobid=getjobjid(jobs,jobid)->pid; kill(jobid,SIGKILL); deletejob(jobs,jobid); } return r; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(!strcmp(argv[0], "quit")){ int i = 0; for (i = 0; i < MAXJOBS; i++) /*If any job is in stopped state then shell will not quit.*/ if (jobs[i].state == ST) { printf("There is stopped job.\n"); return 1; } exit(0); } if(!strcmp(argv[0], "jobs")){ listjobs(jobs); return 1;} if((!strcmp(argv[0], "bg"))||(!strcmp(argv[0], "fg"))){ do_bgfg(argv); return 1;} if(!strcmp(argv[0], "&")) return 1; return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(strcmp(argv[0], "quit") == 0) { // quit command exit(0); } else if(strcmp(argv[0], "jobs") == 0) { // jobs command listjobs(jobs); } else if(strcmp(argv[0], "bg") == 0 || strcmp(argv[0], "fg") == 0) { // bg or fg command do_bgfg(argv); } else { // not a builtin command return 0; } // it was a builtin command return 1; }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. * Return 1 if a builtin command was executed; return 0 * if the argument passed in is *not* a builtin command. */ int builtin_cmd(char **argv) // ~ 25 { // brittany driving // luke driving if(argv[0] == 0){ return 0; } if(strcmp("quit", argv[0]) == 0){ /* int i = 0; for(i; i<MAXJOBS; i++){ if(jobs[i].pid != 0){ if(DEBUG == 1) printf("Killing job %d\n",jobs[i].pid); kill(jobs[i].pid, SIGTERM); // below in sigchild handler } }*/ exit(1); } else if (strcmp("jobs", argv[0]) == 0){ listbgjobs(jobs); return 1; } else if (strcmp("bg", argv[0]) == 0 || strcmp("fg", argv[0]) == 0){ do_bgfg(argv); return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(!strcmp(argv[0], "quit")) /* quit command */ exit(0); if(!strcmp(argv[0], "jobs")){ /* jobs command */ listjobs(jobs); return 1;} if(!strcmp(argv[0], "bg")){ /* jobs command */ do_bgfg(argv); return 1;} if(!strcmp(argv[0], "fg")){ /* jobs command */ do_bgfg(argv); return 1;} if(!strcmp(argv[0], "&")) /* ignore singleton & */ return 1; return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(struct cmdline_tokens cmd_tokens) { int i; char **argv; /** * NOTE: * Based on tutorial the cmd_tokens were to be passed to builtin_cmd * But earlier argv was being passed. * Still using argv but getting that from cmd_tokens instead of passing to the function directly */ int fd; // File discriptor switch (cmd_tokens.builtins) { case BUILTIN_QUIT: // Quit Command exit(0); return 1; break; case BUILTIN_BG: // Command background case BUILTIN_FG: // Command foreground argv = cmd_tokens.argv; // Getting argv here if (argv[1] == NULL) { printf("There are no arguments!"); } else { i = 0; if (argv[1][0] == '%') { i = 1; } while (argv[1][i] != '\0') { if (!isdigit(argv[1][i])) { break; } ++i; } if (argv[1][i] == '\0') { do_bgfg(argv); } else { printf("%s: argument must be a PID or %%jobid\n", argv[0]); } } return 1; break; case BUILTIN_JOBS: if (cmd_tokens.outfile) { fd = open(cmd_tokens.outfile, O_WRONLY, 0); listjobs(jobs, fd); close(fd); } else { listjobs(jobs, STDOUT_FILENO); } return 1; /* Builtin command */ break; default: return 0; /* Not a builtin command */ } }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. * * Requires: * argv should contain less than MAXARGS arguments. * * Effects: * Checks the type of command and calls the appropriate function. * If the command is not a built-in command, the function returns 0. */ static int builtin_cmd(char **argv) { if (strcmp("quit", argv[0]) == 0) { exit(0); } else if (strcmp("jobs", argv[0]) == 0) { listjobs(jobs); return 1; } else if (strcmp("bg", argv[0]) == 0) { do_bgfg(argv); return 1; } else if (strcmp("fg", argv[0]) == 0) { do_bgfg(argv); return 1; } // This is not a build-in command. return 0; }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (!strcmp(argv[0], "quit")) /* quit command */ exit(0); if (!strcmp(argv[0], "jobs")) /* job command show the jobs */ { listjobs(jobs); return 1; } if (!strcmp(argv[0], "bg")) //bg command run do_bgfg { do_bgfg(argv); return 1; } if (!strcmp(argv[0], "fg")) //fg command run do_bgfg { do_bgfg(argv); return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (strcmp(argv[0], "quit") == 0) exit(0); if (strcmp(argv[0], "jobs") == 0) { listjobs(jobs); return 1; } if (strcmp(argv[0], "bg") == 0 || strcmp(argv[0], "fg") == 0) { do_bgfg(argv); return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (strcmp (argv[0], "quit") == 0) // case 1: cmd is quit exit(0); // exit else if (strcmp (argv[0], "jobs") == 0) // case 2: cmd is jobs listjobs(jobs); // listing all jobs else if (strcmp (argv[0], "bg") == 0 || // case 3: cmd is bg or fg strcmp (argv[0], "fg") == 0) do_bgfg (argv); // else return 0; /* not a builtin command */ return 1; }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(!strcmp(argv[0], "quit")){ //If argument is quit exit(0); //exit the shell } if(!strcmp(argv[0], "jobs")){ //If argument is jobs listjobs(jobs); //List all the jobs return 1; } if(!strcmp(argv[0], "bg")){ //If argument is bg do_bgfg(argv); //jump to do_bgfg return 1; } if(!strcmp(argv[0], "fg")){ //If argument is fg do_bgfg(argv); //jump to do_bgfg return 1; } return 0; //not a builtin command }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(!strcmp("quit", argv[0])) exit(0); if (!strcmp("jobs", argv[0])) { listjobs(jobs); return 1; } if (!strcmp("bg", argv[0]) || !strcmp("fg", argv[0])) { do_bgfg(argv); return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (!strcmp(argv[0], "quit")) { /* quit command */ exit(0); } if (!strcmp(argv[0], "jobs")) { /* jobs command */ listjobs(jobs); return 1; } if (!strcmp(argv[0], "bg")) { /* bg command */ do_bgfg(argv); return 1; } if (!strcmp(argv[0], "fg")) { /* fg command */ do_bgfg(argv); // sending it off to the do_bgfg method return 1; } if (!strcmp(argv[0], "&")) { /* Ignore singleton & */ return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv, int *input_fd, int *output_fd) { if (!strcmp(argv[0], "quit")) exit(0); if ((!strcmp(argv[0], "bg")) || (!strcmp(argv[0], "fg"))) { do_bgfg(argv, 1); return 1; } if (!strcmp(argv[0], "jobs")) { listjobs(jobs, 1); return 1; }; if (!strcmp(argv[0], "&")) return 1; return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(argv[1]==NULL && !strcmp(argv[0], "quit")){ /*If the built in command 'quit' is given*/ exit(0); } else if(argv[1]==NULL && !strcmp(argv[0], "jobs")){ listjobs(jobs); return 1; } else if(argv[2]==NULL && (!strcmp(argv[0], "bg") || !strcmp(argv[0], "fg"))){ do_bgfg(argv); return 1; } return 0; /* If not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(strcmp(argv[0], "quit") == 0) // quit exit(0); // exit else if(strcmp(argv[0], "fg") == 0 || strcmp(argv[0], "bg") == 0) { // fg & bg do_bgfg(argv); // do_bgfg return 1; } else if(strcmp(argv[0], "jobs") == 0) { // jobs listjobs(jobs); // print all jobs. return 1; } else return 0; /* not a builtin command */ }
int builtin_cmd(char **argv, int n) { char *command = argv[0]; if (!strcmp(argv[0], "quit")) { /* quit command */ exit(0); } else if (!strcmp("bg", command) || !(strcmp("fg", command))) { do_bgfg(argv,n); return 1; } else if (!strcmp("jobs", command)) { listjobs(jobs); return 1; } return 0; /* not a builtin command */ }
int builtin_cmd(char **argv) { char *cmd = argv[0]; if(strcmp(cmd,"quit")== 0){ exit(0); } else if (strcmp(cmd, "jobs")== 0) { listjobs(jobs, 1); return 1; } else if (!strcmp("bg", argv[0]) || !(strcmp("fg", argv[0]))) { do_bgfg(argv); return 1; } return 0; }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { char* programName = argv[0]; if (strcmp(programName, "quit") == 0) { exit(0); } else if (strcmp(programName, "bg") == 0 || strcmp(programName, "fg") == 0) { do_bgfg(argv); return 1; } else if (strcmp(programName, "jobs") == 0) { listjobs(jobs); return 1; } return 0; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (strcmp((*argv),"quit")==0){ exit(0); } if (strcmp((*argv),"fg")==0 || strcmp(*argv,"bg")==0){ do_bgfg(argv); return 0; } if (strcmp((*argv),"jobs") == 0){ //printf("Do we ever get here?\n"); listjobs(jobs); return 0; } return 1; /* not a builtin command */ }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (!strcmp(argv[0], "quit")) { // exit exit(0); } if (!strcmp("&", argv[0])) { // run in the background return 1; } if (!strcmp( "jobs", argv[0])) { // used to print the job list listjobs(jobs); return 1; } if (!strcmp("fg", argv[0]) || !strcmp("bg", argv[0])) { // and this us useful to specify whether its a fg or bg command do_bgfg(argv); return 1; } return 0; //command not provided }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if(!strcmp(argv[0],"quit")) { exit(0); return 1; } else if((!strcmp(argv[0],"fg")) || (!strcmp(argv[0],"bg"))) //fg or bg { do_bgfg(argv); return 1; } else if(!strcmp(argv[0],"jobs"))//list running and stopped bg jobs { listjobs(jobs); return 1; } else return 0; /* not a builtin command */ }