コード例 #1
0
ファイル: tsh.c プロジェクト: sigmaxz/hw-projects
/*
 * 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
}
コード例 #2
0
ファイル: tsh.c プロジェクト: shilparoys/CS160
/* 
 * 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 */
	}
}
コード例 #3
0
ファイル: tsh.c プロジェクト: anamika2910/IT215
		/*
		 * 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;
		    }   
		}
コード例 #4
0
ファイル: tshref(sai11_12).c プロジェクト: vucuong12/CS_KAIST
/* 
 * 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;
}
コード例 #5
0
ファイル: tsh.c プロジェクト: Drulludanni/sh-lab
/*
 * 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 */
}
コード例 #6
0
ファイル: tsh.c プロジェクト: hexinatgithub/CSAPP
/* 
 * 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 */
}
コード例 #7
0
ファイル: tsh.c プロジェクト: prashantvithani/project-shell
/* 
 * 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 */
}
コード例 #8
0
ファイル: util.c プロジェクト: heapsters/shelldon
/*
 * 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;
}
コード例 #9
0
ファイル: tsh.c プロジェクト: vaibhav-495/Shell
/* 
 * 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 */
}
コード例 #10
0
ファイル: tsh.c プロジェクト: ajpatel910/tiny-shell
/* 
 * 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 */

    
    
}
コード例 #11
0
ファイル: tsh.c プロジェクト: protos37/splab
/* 
 * 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;
}
コード例 #12
0
ファイル: msh.c プロジェクト: luke-c-sargent/439-p0
/* 
 * 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 */
}
コード例 #13
0
ファイル: tsh_n.c プロジェクト: dinesh-kumar-11/shell
/*
 * 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 */
}
コード例 #14
0
/*
 * 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 */
    }
}
コード例 #15
0
ファイル: tsh.c プロジェクト: yejinalicekim/shell
/* 
 * 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;
}
コード例 #16
0
ファイル: tsh.c プロジェクト: nihartrivedi810/shell
/* 
 * 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 */
}
コード例 #17
0
ファイル: tsh.c プロジェクト: MintPaw/College
/* 
	* 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 */
}
コード例 #18
0
ファイル: tsh.c プロジェクト: sanha/SP2015
/*
 * 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;
}
コード例 #19
0
ファイル: tsh.c プロジェクト: RoseySoft/tsh
/* 
 * 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
}
コード例 #20
0
ファイル: tsh.c プロジェクト: whyzidane/CSAPP
/* 
 * 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 */
}
コード例 #21
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")) { /* 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 */
}
コード例 #22
0
ファイル: tsh.c プロジェクト: FDUJiChao/wdan-ics
/* 
 * 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 */
}
コード例 #23
0
ファイル: tsh.c プロジェクト: shaleenx/Linux-Shell
/*
 * 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 */
}
コード例 #24
0
ファイル: tsh.c プロジェクト: Hyunjin95/System_Programming
/*
 * 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 */
}
コード例 #25
0
ファイル: tsh.c プロジェクト: Azureyjt/ICS_LAB
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 */
}
コード例 #26
0
ファイル: tsh.c プロジェクト: FakerLulu/syspro
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;
}
コード例 #27
0
ファイル: tsh.c プロジェクト: athorhallsson/tinyshell
/*
 * 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 */
}
コード例 #28
0
ファイル: tsh.c プロジェクト: raman162/CS351
/* 
 * 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 */
}
コード例 #29
0
ファイル: Unix Shell.c プロジェクト: vchittar/CSC-252
/* 
 * 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
}
コード例 #30
0
ファイル: tsh.c プロジェクト: wwiiiii/CS230-KAIST
/* 
 * 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 */
}