Example #1
0
File: shell.c Project: pucklife/hw1
int shell (int argc, char *argv[]) {
  char *s = malloc(INPUT_STRING_SIZE+1);			/* user input string */
  tok_t *t;			/* tokens parsed from input */
  int lineNum = 0;
  int fundex = -1;
  pid_t pid = getpid();		/* get current processes PID */
  pid_t ppid = getppid();	/* get parents PID */
  

  init_shell();
  
  char buf[1024];
  getcwd(buf, sizeof(buf));

  printf("%s running as PID %d under %d\n",argv[0],pid,ppid);

  
  fprintf(stdout, "%d:%s$ ", lineNum, buf);
  lineNum=1;
  while ((s = freadln(stdin))){
    t = getToks(s); /* break the line into tokens */
    fundex = lookup(t[0]); /* Is first token a shell literal */
    if(fundex >= 0) cmd_table[fundex].fun(&t[1]);
    else {
    	if(t[0]){
      		cmd_fork(t);
      	}
    }
    getcwd(buf, sizeof(buf));
    fprintf(stdout, "%d:%s$ ", lineNum, buf);
    lineNum++;
  }
  return 0;
}
Example #2
0
File: shell.c Project: 560944/hw1
int shell (int argc, char *argv[]) {
    char *s = malloc(INPUT_STRING_SIZE+1);			/* user input string */
    tok_t *t;			/* tokens parsed from input */
    int lineNum = 0;
    int fundex = -1;
    pid_t pid = getpid();		/* get current processes PID */
    pid_t ppid = getppid();	/* get parents PID */
    pid_t cpid, tcpid, cpgid;
https://onedrive.live.com/about/en-us/#
    init_shell();

    printf("%s running as PID %d under %d\n",argv[0],pid,ppid);

    lineNum=0;
    fprintf(stdout, "%d: ", lineNum);
    while ((s = freadln(stdin))) {
        t = getToks(s); /* break the line into tokens */
        fundex = lookup(t[0]); /* Is first token a shell literal */
        if(fundex >= 0) cmd_table[fundex].fun(&t[1]);
        else {
            //fprintf(stdout, "This shell only supports built-ins. Replace this to run programs as commands.\n");

            cmd_fork(t);


        }
        fprintf(stdout, "%d: ", lineNum);
    }
    return 0;
}
Example #3
0
int			update_fork_incant(t_serv *serv, double elapsed, t_client *tmp)
{
  if (tmp->incanting)
    {
      tmp->incant_time -= elapsed / 1000000;
      if (tmp->incant_time <= 0)
	if (cmd_end_incantation(serv, tmp) == EXIT_FAILURE)
	  return (EXIT_FAILURE);
    }
  if (tmp->forking)
    {
      tmp->fork_time -= elapsed / 1000000;
      if (tmp->fork_time <= 0)
	if (cmd_fork(serv, tmp, NULL) == EXIT_FAILURE)
	  return (EXIT_FAILURE);
    }
  if (check_death(serv, tmp) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}