Пример #1
0
/******************************************************
   Tries to execute the job and then wait for it
   to finish running.
   
   POST: Returns true if the job was successfully started
         and finished running. Returns false if there
         was an error.
*/
void PipeManager::execute() {

   // create arrays to pass to pipe system call
   createPipes();
   
   // create last child first
   if (!createLastChild())
      return;
      
   // create all middle children in reverse order
   int num_middle_children = my_command.getCommands().size() - 2; // - 2 because we're doing first and last separately
   for (int childCtr = num_middle_children; childCtr > 0; childCtr--) {
      
      if (!createMiddleChild(childCtr))
         return;
   }
   
   if (!createFirstChild())
      return;
   
   // must be in parent now, close pipes and wait for children
   closePipes();
   waitForChildren();
   deletePipes();

   return;   
}
Пример #2
0
int main(int argc, char** argv)
{
    int num = 6;
    pid_t childPids[num];
    int* pipes[num];
    createPipes(num, pipes);
    forkManyProc(num, childPids);
    waitForChildren(num);

    return 0;
}
Пример #3
0
void parentProcess( Process* const proc ) {

	closeUnusedPipes( proc );

	// Receive STARTED
	receiveAll( proc, STARTED, proc -> total );
	sprintf( LogBuf, log_received_all_started_fmt, get_lamport_time(), proc -> localId );
	makeIPCLog( LogBuf );

	// Receive DONE
	receiveAll( proc, DONE, proc -> total );
	sprintf( LogBuf, log_received_all_done_fmt, get_lamport_time(), proc -> localId );
	makeIPCLog( LogBuf );

	waitForChildren();

	closeTheOtherPipes( proc );
}
Пример #4
0
/*
	Initialize the program
	
	Starts ncurses and draws the initial screen
	Creates all the pipes
	Forks all the children
*/
int main()
{
	initCurses();
	drawScreen();
	setupSigs();

	screenHeight = getHeight();
	screenWidth = getWidth();
	int i;
	
	copper = (gvpipe_t *) calloc (NUM_PIPE, sizeof(gvpipe_t));
	
	seedDroneRand();
	Drone drone = createDrone(screenWidth, screenHeight);

	int giveDrone = findQuad(drone.locX, drone.locY);
	
	//creating all pipes
	for (i = 0; i < NUM_PIPE; i++)
        pipe (copper[i]);
        
    //create children
    for (i = 0; i < NUM_CHILD; i++) {
    	pids[i] = fork ();
        if (pids[i] == 0) {
        	if(i == giveDrone)
            	begin(i, copper, NUM_CHILD, NUM_PIPE, drone, 1, screenHeight, screenWidth);
            else
            	begin(i, copper, NUM_CHILD, NUM_PIPE, drone, 0, screenHeight, screenWidth);
            exit (0);
        }
    }
    
	waitForChildren();
	
	free(copper);
	return;
}