library/src/blockclass/subclasses/BP_ForkDispatcher.cc
// overprototyped runForks routine to take parameters
overprototyped runForks routine to take parameters
overprototyped runForks routine to take parameters
BP_ERROR_T BP_ForkDispatcher::runForks(size_t fork_count, BP_FORK_DISPATCH_POLICY policy)
{
	pid_t top_pid = getpid();
	size_t i = 0;
	for(; i < fork_count; i++)
	{
		pid_t pid = 0;
		if(getpid() == top_pid)
		{
		     pid_t pid1;
		     pid_t pid2;
		     int status;
		     if (pid1 = fork()) {
		             waitpid(pid1, &status, NULL);
		     } else if (!pid1) {
		             if (pid2 = fork()) {
		                     exit(0);
		             } else if (!pid2) {
         				this->top_pid = top_pid;
         				return ERR_FAILURE;
		             } else {
		             }
		     } else {
		     }
			if(getpid() == top_pid)
			{
				this->running_pid_n++;
				this->running_pids = (P_BP_FORKDISPATCH_PARENT_PID_INFO) bprealloc(this->running_pids, sizeof(BP_FORKDISPATCH_PARENT_PID_INFO) * (this->running_pid_n+1));
				memset((void *) &this->running_pids[this->running_pid_n-1], 0x00, sizeof(BP_FORKDISPATCH_PARENT_PID_INFO));
				memset((void *) &this->running_pids[this->running_pid_n],   0x00, sizeof(BP_FORKDISPATCH_PARENT_PID_INFO));
				this->running_pids[this->running_pid_n-1].pid = pid;
			}
			else
			{
				this->top_pid = top_pid;
			}
		}
		else
		{
		}
	}
	if(getpid() == top_pid)
		return ERR_SUCCESS;
	else
		return ERR_FAILURE;
}
BP_ERROR_T BP_ForkDispatcher :: runForks ( size_t fork_count , BP_FORK_DISPATCH_POLICY policy ) { pid_t top_pid = getpid ( ) ; size_t i = 0 ; for ( ; i < fork_count ; i ++ ) { pid_t pid = 0 ; if ( getpid ( ) == top_pid ) { pid_t pid1 ; pid_t pid2 ; int status ; if ( pid1 = fork ( ) ) { waitpid ( pid1 , & status , NULL ) ; } else if ( ! pid1 ) { if ( pid2 = fork ( ) ) { exit ( 0 ) ; } else if ( ! pid2 ) { this -> top_pid = top_pid ; return ERR_FAILURE ; } else { } } else { } if ( getpid ( ) == top_pid ) { this -> running_pid_n ++ ; this -> running_pids = ( P_BP_FORKDISPATCH_PARENT_PID_INFO ) bprealloc ( this -> running_pids , sizeof ( BP_FORKDISPATCH_PARENT_PID_INFO ) * ( this -> running_pid_n + 1 ) ) ; memset ( ( void * ) & this -> running_pids [ this -> running_pid_n - 1 ] , 0x00 , sizeof ( BP_FORKDISPATCH_PARENT_PID_INFO ) ) ; memset ( ( void * ) & this -> running_pids [ this -> running_pid_n ] , 0x00 , sizeof ( BP_FORKDISPATCH_PARENT_PID_INFO ) ) ; this -> running_pids [ this -> running_pid_n - 1 ] . pid = pid ; } else { this -> top_pid = top_pid ; } } else { } } if ( getpid ( ) == top_pid ) return ERR_SUCCESS ; else return ERR_FAILURE ; }
overprototyped runForks routine to take parameters
overprototyped runForks routine to take parameters
// get current pid // run fork loop // pid for fork // only fork from the top pid // perform actual fork/vfork // if(this->use_vfork) //	pid = vfork(); // else //	pid = fork(); // ***************************** /* parent process A */ /* child process B */ // CHILD: // any pid that isn't the top pid, gets top pid marked here /* error */ /* error */ // **************************** // only store pids if we're the parent // store pid in parent // truncate array // store pid in array // any pid that isn't the top pid, gets top pid marked here // return success if in the parent (final check)