示例#1
0
int	launch_redir_left(t_cmd *cmd, t_system *sys)
{
  int	prc_pipe[2];
  pid_t	first;
  pid_t	second;

  if (pipe(prc_pipe) == -1)
    return (SIGRTN_NOERR);
  sys->wait = 0;
  if (cmd->nxtsym == SYM_REDIR_LFT)
    first = launch_redir_out(cmd->next, sys, prc_pipe);
  else
    first = launch_redir_heredoc(cmd->next, sys, prc_pipe);
  if (first == 0)
    return (SIGRTN_EXIT);
  remove_nxtcmd(cmd);
  second = launch_pipe_in(cmd, sys, prc_pipe);
  if (second == 0)
    return (SIGRTN_EXIT);
  close(prc_pipe[0]);
  close(prc_pipe[1]);
  wait_proc(sys, first);
  wait_proc(sys, second);
  sys->wait = 1;
  return (SIGRTN_NOERR);
}
示例#2
0
int main(int argc, char **argv)
{
		pid_t _pid_list[_PORC_NUM_];
		int i=0;
		for(; i<_PORC_NUM_; i++)
		{
			_pid_list[i] = _DEFAULT_PID_;
		}
		if( creat_proc(_pid_list, sizeof(_pid_list)/sizeof(_pid_list[0])) == 0 )
		{ //watch out!!! sizeof*/sizeof*[0] !!!!
			printf("%s :create all proc success!\n",__FUNCTION__);
		}
		else
		{
			printf("%s :not all proc create success!\n",__FUNCTION__);
		}
		if( wait_proc(_pid_list, sizeof(_pid_list)/sizeof(_pid_list[0])) == 0 )
		{
			printf("%s :wait all proc success!\n",__FUNCTION__);
		}
		else
		{
			printf("%s :not wait all proc success!\n",__FUNCTION__);
		}
		return 0;
}
int main(int argc,char *argv[]){
  char *TimeMAX_wait = NULL;
  int nPA,nPB;

  parse_argv(argc,argv,&nPA,&nPB,&TimeMAX_wait);
  install_signal_handler();

  init_TProc(nPA,nPB);

  create_proc_byclass(PB,nPB,0,TimeMAX_wait);
  create_proc_byclass(PA,nPA,nPB,TimeMAX_wait);

  wait_proc(nPA);

  printf("[MANAGER] Program Termination (all PA processes terminated)\n");
  termProc();
  freeResources();

  return EXIT_SUCCESS;
}
示例#4
0
int main()
{
int i, j;


int pidf,id_wait;
void dt_shareG();

   mc_var_inic ();

   def_task (0, "multiplicarAB", sizeof (__multiplicarAB__));
   def_task (1, "multiplicarCD", sizeof (__multiplicarCD__));
   def_task (2, "sumar", sizeof (__sumar__));
   def_task (3, "print", sizeof (__print__));
   id_wait=sem_wait_inic(4);


   for (i=0; i<100; i++){
        for (j = 0; j < 100; j++)
        {
            /*A[i][j] = i + j;
            B[i][j] = i + 2*j;
            C[i][j] = i*2 + j*3;
            D[i][j] = i*2 + j;*/
            sharedG->A[i][j] = 1;
            sharedG->B[i][j] = 1;
            sharedG->C[i][j] = 1;
            sharedG->D[i][j] = 1;
        }
    }

    alloc_proc(4);

      
   pidf = exec_task (0, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplicarAB();
      end_task();            /* --- rs31() - create --- */
   }

      
   pidf = exec_task (1, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplicarCD();
      end_task();            /* --- rs31() - create --- */
   }


    wait_all();

      
   pidf = exec_task (2, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      sumar();
      end_task();            /* --- rs31() - create --- */
   }

    
    
   wait_proc (2);    /* --- wait_proc() --- */


      
   pidf = exec_task (3, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      print();
      end_task();            /* --- rs31() - create --- */
   }


       wait_all();      /* --- rs307()  */
   end_program();
   remove_semaforo(id_wait);
return 0;
}
示例#5
0
int main(int argc,char **argv,char **environ)
{
	unsigned int seconds = 0;
	int seconds_flag = 0;
	unsigned int wait_seconds;
	unsigned int proc_seconds;
	int wait_mode = 0;
	int proc_wait = 0;
	char **cmd_argv = NULL;
	int  child_pid = 0;
	int  job_count_flag = 0;
	int  job_count_exit = 0;
	unsigned long job_counter    = 1;
	int c;
	int first_do_flag = 0;
	int exitcode_flag = 0;
	int exitcode,exitcodewk;
	int init_sec_flag = 0;
	unsigned int init_seconds = 0;
	extern char *optarg;
	extern int optind, opterr, optopt;

	
	setvbuf(stdout,NULL,_IONBF,0);
	setvbuf(stdin,NULL,_IONBF,0);

	progname = *(argv + 0);

	seconds_flag  = 0;
	first_do_flag = 0;
	exitcode_flag = 0;
	exitcode = exitcodewk = 0;
	job_counter   = 1;
	init_sec_flag = 0;
	init_seconds = 0;

	while(1)
	{
		c = getopt(argc,argv,"ae:TWc:C:vhlLi:");

		if(c == EOF)
			break;

		switch(c)
		{
			case 'a':
				first_do_flag = 1;
				init_sec_flag = 0;
				break;
			case 'e':
				exitcode_flag = 1;
				exitcode = strtoul(optarg, (char **)NULL, 10);
				break;
			case 'T':
				wait_mode = 1;
				break;
			case 'W':
				proc_wait = 1;
				break;
			case 'C':
				job_count_exit = 1;
			case 'c':
				job_count_flag = 1;
				job_counter = strtoul(optarg, (char **)NULL, 10);
				break;
			case 'v':
				printf("%s\n",RCSid);
			case 'h':
				print_help();
				return 0;
				break;
			case 'l':
				print_time_flag = 1;
				break;
			case 'L':
				print_time_flag = 2;
				break;
			case 'i':
				init_sec_flag = 1;
				first_do_flag = 0;
				init_seconds = get_second(optarg);
				break;
			default :
				return 127;
		}
	}

	if (optind < argc)
	{
		seconds = get_second(argv[optind]);
		optind++;
	}
	if (optind < argc)
	{
		cmd_argv = argv + optind;
	}

	if((seconds == 0) || (cmd_argv == NULL))
	{
		print_help();
		exit(0);
	}

#if 1
	{
		int i;

		print_time();
		printf("cron_job_start : %u %d %d %d\n",seconds,wait_mode,proc_wait,first_do_flag);
		print_time();
		printf("cron_job_count : %u %d %d\n",job_counter,job_count_flag,job_count_exit);
		print_time();
		printf("cron_job_exit  : %d %d\n",exitcode_flag,exitcode);

		print_time();
		printf("cron_job_args  : ");
		for(i = 0;cmd_argv[i] != NULL;i++)
		{
			printf("[%s]",cmd_argv[i]);
		}
		printf("\n");
	}
#endif

	wait_seconds = seconds;

	/* main loop */
	while((job_counter != 0) || (job_count_exit == 0))
	{
		do_job = 0;
		do_job_force = 0;
		proc_seconds = 0;

		if(init_sec_flag != 0)
		{
			wait_seconds = time(NULL);
			if(init_seconds <= wait_seconds)
				wait_seconds = seconds;
			else
				wait_seconds = init_seconds - wait_seconds;

			print_time();
			printf("cron_job_init_time  : %u\n",wait_seconds);
		}
		init_sec_flag = 0;

		signal(SIGALRM, alarm_signal);
		signal(SIGHUP,  hup_signal);

		if((first_do_flag != 0) || (timer_wait(wait_mode,wait_seconds) != 0))
		{

			signal(SIGALRM, SIG_IGN);
			signal(SIGHUP,  SIG_IGN);

			if(check_cronexec_do( ((do_job_force != 0) || (job_counter > 0)) ) != 0)
			{
				if((do_job_force != 0) || (job_counter > 0))
				{
					child_pid = cron_job(cmd_argv,environ);

					if(child_pid > 0)
						proc_seconds = wait_proc(child_pid,exitcode_flag,exitcode,&exitcodewk);

					if((job_count_flag != 0) && (job_counter > 0))
						job_counter--;
				}
			}
		}

		first_do_flag = 0;

		wait_seconds = seconds;
		if(proc_wait != 0)
			wait_seconds -= (clock_t2seconds(proc_seconds) % seconds);
	}
 
	print_time();
	printf("cron_job_end\n");

	return 0;
}