Example #1
0
File: shell.c Project: 707831/hw
int cmd_exec(tok_t arg[]) {
  
  int pid;
  char* pathname = arg[0];
  pid            = fork();
  
  //Child Process
  if (pid == 0) {
  
    pathname = split(arg);
    process_redirection(arg + 1);
    execv(pathname, arg);
    exit(0);
    
  }
    
  else if(pid < 0) {
    
    fprintf(stderr, "Failed to execute: %s\n", arg[0]);
    return -1;
    
  }
    
  //Parent Process
  wait(NULL);
  return 1;
  
}
Example #2
0
int non_pipe_process(char ***cmd_mat) {
	int retval;
	if ((retval = execute_non_forking(*cmd_mat)) == 2) {
			long int sec1,uSec1;					//set up time variables
			etimeStart(&sec1,&uSec1);		//start time
		pid_t pid = fork_check();
		if (pid == 0) { // child
			char **new_subcmd = process_redirection(*cmd_mat);
			execute_forking(new_subcmd);
		} else { // parent
			int status;
			if (strcmp(process_redirection(*cmd_mat)[0], "limits") == 0) {
				 limits(pid);
	   	} else if (strcmp(process_redirection(*cmd_mat)[0], "etime") == 0) {
				 etimeFinish(pid,sec1,uSec1);
			} else
				waitpid(pid, &status, 0);
			retval = 1;
		}
	}
	return retval;
}