Ejemplo n.º 1
0
void  main(void)
{
     pid_t   pid1, pid2, pid;
     int     status;
     int     i;
     char    buf[BUF_SIZE];
     
     printf("*** Parent is about to fork process 1 ***\n");
     if ((pid1 = fork()) < 0) {
          printf("Failed to fork process 1\n");
          exit(1);
     }
     else if (pid1 == 0) 
          ChildProcess("First", "   ");

     printf("*** Parent is about to fork process 2 ***\n");
     if ((pid2 = fork()) < 0) {
          printf("Failed to fork process 2\n");
          exit(1);
     }
     else if (pid2 == 0) 
          ChildProcess("Second", "      ");

     ParentProcess();
     sprintf(buf, "*** Parent enters waiting status .....\n");
     write(1, buf, strlen(buf));
     pid = wait(&status);
     sprintf(buf, "*** Parent detects process %d was done ***\n", pid);
     write(1, buf, strlen(buf));
     pid = wait(&status);
     printf("*** Parent detects process %d is done ***\n", pid);
     printf("*** Parent exits ***\n");
     exit(0);
}
Ejemplo n.º 2
0
void CrashHandler::CrashHandlerHandleArgs( int argc, char* argv[] )
{
	if( argc == 2 && !strcmp(argv[1], CHILD_MAGIC_PARAMETER) )
	{
		ChildProcess();
		exit(0);
	}
}
Ejemplo n.º 3
0
void  main(void)
{
     pid_t  pid;

     pid = fork();
     if (pid == 0)
          ChildProcess();
     else
          ParentProcess();
}
Ejemplo n.º 4
0
void  main(void)
{
     pid_t  pid;

     pid = fork();
	 if (pid == -1)
        {
            printf ("Can't fork!!\n"); //обработчик ошибок при вызове fork
            exit (-1);
        }
     else if (pid == 0) 
          ChildProcess();
     else 
          ParentProcess();
}
Ejemplo n.º 5
0
int main()
{
    int status;
    pid_t pid;
    
    mem_alloc = (int*) malloc(sizeof(int));
    *mem_alloc = 1000;

    pid = fork();
    
    if (pid == 0)
        ChildProcess();
    else
        ParentProcess();

    wait(&status);
    return 0;
}
Ejemplo n.º 6
0
int main()
{
	int pid, cid;
	pid = getpid();

	std::cout << "Fork demo, I am the parent (pid = )" << pid << ")\n";

	if (!fork())
	{
		cid = getpid();
		std::cout << "I am the child (cid=" << cid << ") of (pid = )" << pid << ")\n";
		ChildProcess();
		exit(0);
	}

	std::cout << "Parent waiting here for the child...\n";
	wait(NULL); // Wait for child to terminate

	std::cout << "Child finished, parent quitting too";
}
Ejemplo n.º 7
0
int main( int argc, char ** argv ) {

   int childpid;
   Socket s1('s', false),	// Create a socket with SOCK_STREAM
     *s2;

   s1.Bind( 9876 );		// Port to access this mirror server
   s1.Listen( 5 );		// Set backlog queue to 5 conections

   for( ; ; ) {
      s2 = s1.Accept();	 	// Wait for a conection
      childpid = fork();	// Create a child to serve the request
      if ( childpid < 0 )
         perror("server: fork error");
      else if (0 == childpid) {	// child code
         s1.Close();		// Close original socket in child
         ChildProcess( s2 );
      }
      s2->Close();		// Close socket in parent
   }
}
Ejemplo n.º 8
0
void Worker::run()
{
    keepRunning = true;
    int childpid;
    Socket *s2;	// Create a socket with SOCK_STREAM


    s1->Bind( puerto );		// Port to access this mirror server
    s1->Listen( 5 );		// Set backlog queue to 5 conections

    while(keepRunning) {
       s2 = s1->Accept();	 	// Wait for a conection
       childpid = fork();	// Create a child to serve the request
       if ( childpid < 0 )
          perror("server: fork error");
       else if (0 < childpid) {	// child code
          s1->Close();		// Close original socket in child
          ChildProcess( s2 );
       }
       s2->Close();		// Close socket in parent
    }
}
Ejemplo n.º 9
0
int ProcessExternalCommand (struct data * d, struct comand * c)
{
	int status = COMMAND_OK;
	pid_t pid;
	int s = 0;
	pid = fork();
	if (pid == -1)
	{
		perror ("Crytical error: fork did not work");
		return RUN_ERROR;
	}
	if (pid == 0)
		ChildProcess (d, c);
	else
	{
		if (ClosePipe (&(d->in), &(d->out)))
			status = COMMAND_FAIL;
	}
	if (!d->bg)
	{
		if (d->pp)
		{
			++ d->i;
			AddToPipeList (pid, &(d->plist));
		}
		else
		{
			waitpid (pid, &s, 0);
			if (WIFEXITED (s))
			{
				if (WEXITSTATUS (s) != COMMAND_OK)
					status = COMMAND_FAIL;
			}
		}
	}
	return status;
}