library/src/blockclass/subclasses/BP_ForkDispatcher.cc
BP_ERROR_T BP_ForkDispatcher::runForks()
{


	// get current pid
	pid_t top_pid = getpid();

	// run fork loop
	size_t i = 0;
	for(; i < this->max_running_pids; i++)
	{

		// pid for fork
		pid_t pid = 0;

		// only fork from the top pid
		if(getpid() == top_pid)
		{

			// perform actual fork/vfork
			if(this->use_vfork)
				pid = vfork();
			else
				pid = fork();

			// only store pids if we're the parent
			if(getpid() == top_pid)
			{

				// store pid in parent
				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));

				// truncate array
				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));

				// store pid in array
				this->running_pids[this->running_pid_n-1].pid = pid;

			}
			else
			{
				this->top_pid = top_pid;
			}

		}
		else /* now in child */
		{

			// set current pid in class
			this->curr_pid = getpid();

			// set fork index for easy lookups
			this->curr_fork_index = i;

			// fork with err success if we are the child
			if(pid == (pid_t) 0)
				return ERR_FAILURE;

		}

	}

	// return success if in the parent (final check)
	if(getpid() == top_pid)
		return ERR_SUCCESS;
	else
		return ERR_FAILURE;

}
// runs all configured forks in the class (aka dispatch all).  Will
// never run more than the classes maximum running pids object.
runs all configured forks in the class (aka dispatch all).  Will
never run more than the classes maximum running pids object.
runs all configured forks in the class ( aka dispatch all ) . Will never run more than the classes maximum running pids object .
BP_ERROR_T BP_ForkDispatcher::runForks()
{
	pid_t top_pid = getpid();
	size_t i = 0;
	for(; i < this->max_running_pids; i++)
	{
		pid_t pid = 0;
		if(getpid() == top_pid)
		{
			if(this->use_vfork)
				pid = vfork();
			else
				pid = fork();
			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 
		{
			this->curr_pid = getpid();
			this->curr_fork_index = i;
			if(pid == (pid_t) 0)
				return ERR_FAILURE;
		}
	}
	if(getpid() == top_pid)
		return ERR_SUCCESS;
	else
		return ERR_FAILURE;
}
BP_ERROR_T BP_ForkDispatcher :: runForks ( ) { pid_t top_pid = getpid ( ) ; size_t i = 0 ; for ( ; i < this -> max_running_pids ; i ++ ) { pid_t pid = 0 ; if ( getpid ( ) == top_pid ) { if ( this -> use_vfork ) pid = vfork ( ) ; else pid = fork ( ) ; 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 { this -> curr_pid = getpid ( ) ; this -> curr_fork_index = i ; if ( pid == ( pid_t ) 0 ) return ERR_FAILURE ; } } if ( getpid ( ) == top_pid ) return ERR_SUCCESS ; else return ERR_FAILURE ; }
runs all configured forks in the class (aka dispatch all).
runs all configured forks in the class ( aka dispatch all ) .
// get current pid // run fork loop // pid for fork // only fork from the top pid // perform actual fork/vfork // only store pids if we're the parent // store pid in parent // truncate array // store pid in array /* now in child */ // set current pid in class // set fork index for easy lookups // fork with err success if we are the child // return success if in the parent (final check)