Exemplo n.º 1
0
int main(int argc, char * argv[]) {
  int listenfd;
  int num;
  int i;
  
  if (argc < 2) {
    print_usage();
  }
  
  num = atoi(argv[1]);
  idle_num = num;

  fprintf(stdout, "%d Channels are running ... \n", num);
  
  //to lock the log file
  lock_init(LOG_LOCK);
  
  listenfd = init_server();
  pids = (pid_t *)(malloc(sizeof(pid_t) * num));
  for (i = 0; i < num; i++) {
    pids[i] = child_make(i, listenfd);
  }

  signal_wrapper(SIGINT, sig_int);
  close_wrapper(listenfd);
  while(true)
    pause();
  return 0;
}
Exemplo n.º 2
0
/*
 * main - The shell's main routine 
 */
int main(int argc, char **argv) 
{
  char c;
  char cmdline[MAXLINE];

  verbose = 0;

  /* Redirect stderr to stdout (so that driver will get all output
   * on the pipe connected to stdout) */
  dup2(1, 2);

  /* Parse the command line */
  while ((c = getopt(argc, argv, "hv")) != EOF) {
    switch (c) {
    case 'h':             /* print help message */
      usage();
      break;
    case 'v':             /* emit additional diagnostic info */
      verbose = 1;
      break;
    default:
      usage();
    }
  }

  /* Install the signal handlers */

  /* These are the ones you will need to implement */
  signal_wrapper(SIGINT,  sigint_handler);   /* ctrl-c */
  signal_wrapper(SIGTSTP, sigtstp_handler);  /* ctrl-z */
  signal_wrapper(SIGCHLD, sigchld_handler);  /* Terminated or stopped child */
  

  /* Initialize the job list */
  jobs_initjobs();

  printf("\nType help to find out all the available commands in mshell\n\n");
  
  /* Execute the shell's read/eval loop */
  while (1) {
	char* plop;
    /* Read command line */
    printf("%s", prompt);
	
	plop = fgets(cmdline, MAXLINE, stdin);
      
    if (( plop== NULL) && ferror(stdin)) {
      fprintf(stdout, "fgets error (%d) (%d)\n",plop==NULL?1:0,ferror(stdin)?1:0);
      exit(EXIT_FAILURE);
    }
    if (feof(stdin)) { /* End of file (ctrl-d) */
      fflush(stdout);
      exit(EXIT_SUCCESS);
    }


    /* Evaluate the command line */
	if (cmdline[0] != '\n') /* evaluate the command line only it is not empty */
	{
		cmdline[strlen(cmdline)-1] = '\0';  /* remove the '\n' at the end */
		eval(cmdline);
		fflush(stdout);
  	}
  } 
    
  exit(EXIT_SUCCESS); /* control never reaches here */
}