コード例 #1
0
ファイル: daemon.cpp プロジェクト: spito/dp
void Daemon::grouped( Channel channel ) {
    NOTE();

    OutputMessage response( MessageType::Control );
    if ( _state != State::FormingGroup ) {
        response.tag( Code::Refuse );
        channel->send( response );
        return;
    }

    Channel top, bottom;
    std::tie( top, bottom ) = Communicator::socketPair();

    response.tag( Code::OK );
    channel->send( response );

    int pid = ::fork();
    if ( pid == -1 )
        throw brick::net::SystemException( "fork" );
    if ( pid == 0 )
        becomeChild( std::move( bottom ) );
    else {
        _childPid = pid;
        becomeParent( std::move( top ) );
    }
}
コード例 #2
0
void OptimisticTickSyncAlgo::createSpeculativeProcess()
{
	pid_t forkpid = fork();
	if (-1 == forkpid) {
		/* I am the parent, and an error was detected */
		perror("createSpeculativeProcess: fork");
		exit(0);
	}
	else if (0 == forkpid) {
		/* I am a child */
		becomeChild();
	}
	else {
		/* I am a parent */
		gotChild(forkpid);
	}
}