/*
  Handle all processes
 */
void handle_processes()
{
  int c1 = fork();
  int c2;

  // means this is parent process
  if(c1 != 0)
  {
    c2 = fork();
  }

  // make sure no failures with fork
  if(c1 < 0 || c2 < 0)
  {
    perror("Something failed with fork...\n");
    _exit(1);
  }

  /* Handle Each process */
  /* Handle Child 1 */
  if(c1 == 0)
  {
    handle_child1();
  }
  /* Handle Child 2 */
  else if(c2 == 0)
  {
    handle_child2();
  }
  /* Handle Parent Process */
  else // if c1 && c2 != 0
  {
    handle_parent(c1, c2);
  }
}
Example #2
0
File: shell.c Project: vaot/various
void handle_fork(pid_t pid, _Bool in_background, char *tokens[]) {
  if (pid == 0) {
    handle_child(tokens, in_background);
  } else if (pid < 0) {
    fprintf(stderr, "Please, make sure to specify a positive integer.\n");
  } else {
    handle_parent(pid, in_background, tokens);
  }
}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (argc == 1) // parent
    ACE_ASSERT (handle_parent (argv[0]) == 0);
  else
    ACE_ASSERT (handle_child () == 0);

  ACE_UNUSED_ARG (argv);
  return 0;
}
Example #4
0
void begin_session(session_t *sess)
{
    /*开启接收带外数据*/
    activate_oobinline(sess->ctrl_fd);

    /*
    	int sockfds[2];
    	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds) < 0)
    	{
    		ERR_EXIT("socketpair");
    	}
    */
    /*初始化内部进程间通讯通道*/
    priv_sock_init(sess);

    pid_t pid;
    pid = fork();
    if (pid < 0)
    {
        ERR_EXIT("fork");
    }

    if (pid == 0)
    {
        //ftp服务进程
        /*
        close(sockfds[0]);
        sess->child_fd = sockfds[1];
        */
        /*设置子进程环境*/
        priv_sock_set_child_context(sess);
        handle_child(sess);
    }
    else
    {
        //nobody进程
        /*
        close(sockfds[1]);
        sess->parent_fd = sockfds[0];
        */
        /*设置父进程环境*/
        priv_sock_set_parent_context(sess);
        handle_parent(sess);
    }
}
/* File handling starts here and tasks are assigned to each process */
void parse_file(FILE *input)
{
  switch (*identifier)
  {
  case PARENT_IDENTIFIER:
    handle_parent(input);
    break;
  case MAPPER_IDENTIFIER:
    handle_mapper();
    break;
  case REDUCER_IDENTIFIER:
    handle_reducer();
    break;
  default:
    exit(1);
    break;
  }
}
Example #6
0
void begin_session(session_t* psess)
{
	
	priv_sock_init(psess);

	pid_t pid = fork();
	if (pid == -1)
		ERR_EXIT("fork");
	if (pid == 0)
	{//服务进程
		priv_sock_set_child_context(psess);
		handle_child(psess);
	}
	else if(pid > 0)
	{//nobody进程
		priv_sock_set_parent_context(psess);
		handle_parent(psess);
	}
}
Example #7
0
void begin_session(session_t *sess)
{
    activate_oobinline(sess->ctrl_fd);
    priv_sock_init(sess);
    pid_t pid;
    pid = fork();
    if(pid < 0)
        ERR_EXIT("fork");

    if(pid == 0)
    {
        /* ftp process */
        priv_sock_set_child_context(sess);
        handle_child(sess);
    }else
    {
        /* nobody process */
        priv_sock_set_parent_context(sess);
        handle_parent(sess);
    }
}
Example #8
0
void begin_session(session_t *sess)
{
/*	struct passwd *pw = getpwnam("nobody");
	if(pw == NULL)
		return;

	if(setegid(pw->pw_gid) < 0)
		ERR_EXIT("setegid");
	if(seteuid(pw->pw_uid) < 0)
		ERR_EXIT("seteuid");*/

	int sockfds[2];
	if(socketpair(PF_UNIX, SOCK_STREAM, 0, sockfds) < 0)
		ERR_EXIT("sockpair");

    priv_sock_init(sess);

	pid_t pid;
	pid = fork();

	if(pid < 0)
		ERR_EXIT("fork");

	if (pid == 0)
	{
/*		close(sockfds[0]);
		sess->parent_fd = sockfds[1];*/

        priv_sock_set_child_context(sess);
		handle_child(sess);
	}
	else
	{
/*		close(sockfds[1]);
		sess->child_fd = sockfds[0];*/

        priv_sock_set_parent_context(sess);
		handle_parent(sess);
	}
}