Beispiel #1
0
void main(){

	pid_t father_pid = getpid();
	pid_t ps_pids[2];
	int forkReturn, option;

	if( getpid() == father_pid ){
		switch( forkReturn = fork() ){
			case ERROR:
				forkError();
				break;
			case AT_SON:
				signal(SIGUSR1, ps1sayHi);
				break;
			default:
				ps_pids[0] = forkReturn;
				break;
		}

		switch( forkReturn = fork() ){
			case ERROR:
				forkError();
				break;
			case AT_SON:
				signal(SIGUSR1, ps2sayHi);
				break;
			default:
				ps_pids[1] = forkReturn;
				break;

		}
	}

	if(getpid() == father_pid){
		printf("Elige el orden de ejecucion de los dos procesos: (12 o 21)\n");
		scanf("%d", &option);

		printf("\n\t%d", option);
		switch(option){
			case 12:
				kill(ps_pids[0], SIGUSR1);
				kill(ps_pids[1], SIGUSR1);
				break;
			case 21:
				kill(ps_pids[1], SIGUSR1);
				kill(ps_pids[0], SIGUSR1);
				break;
		}		
	}
}
Beispiel #2
0
int LshttpdMain::startChild(ChildProc *pProc)
{
    if (!pProc->m_pBlackBoard)
    {
        pProc->m_pBlackBoard = allocateBlackBoard();
        if (!pProc->m_pBlackBoard)
            return LS_FAIL;
    }
    pProc->m_iProcNo = getFirstAvailSlot();
    if (pProc->m_iProcNo > HttpServerConfig::getInstance().getChildren())
        return LS_FAIL;
    preFork();
    pProc->m_pid = fork();
    if (pProc->m_pid == -1)
    {
        forkError(errno);
        return LS_FAIL;
    }
    if (pProc->m_pid == 0)
    {
        //child process
        cpu_set_t       cpu_affinity;

        if (GlobalServerSessionHooks->isEnabled(LSI_HKPT_WORKER_POSTFORK))
            GlobalServerSessionHooks->runCallbackNoParam(LSI_HKPT_WORKER_POSTFORK,
                    NULL);

        PCUtil::getAffinityMask(s_iCpuCount, pProc->m_iProcNo - 1, 1,
                                &cpu_affinity);
        PCUtil::setCpuAffinity(&cpu_affinity);
        m_pServer->setBlackBoard(pProc->m_pBlackBoard);
        m_pServer->setProcNo(pProc->m_iProcNo);
        //setAffinity( 0, pProc->m_iProcNo);  //TEST: need uncomment and debug
        releaseExcept(pProc);
        m_pServer->reinitMultiplexer();
        m_pServer->enableAioLogging();
        if ((HttpServerConfig::getInstance().getUseSendfile() == 2)
            && (m_pServer->initAioSendFile() != 0))
            return LS_FAIL;
        close(m_fdAdmin);
        snprintf(argv0, 80, "openlitespeed (lshttpd - #%02d)", pProc->m_iProcNo);
        return 0;
    }

    if (GlobalServerSessionHooks->isEnabled(LSI_HKPT_MAIN_POSTFORK))
        GlobalServerSessionHooks->runCallbackNoParam(LSI_HKPT_MAIN_POSTFORK, NULL);
    postFork(pProc->m_pid);
    m_childrenList.push(pProc);
    pProc->m_iState = CP_RUNNING;
    setChildSlot(pProc->m_iProcNo, 1);

    ++m_curChildren;
    return pProc->m_pid;
}
int LshttpdMain::startChild( ChildProc * pProc )
{
    if ( !pProc->m_pBlackBoard )
    {
        pProc->m_pBlackBoard = allocateBlackBoard();
        if ( !pProc->m_pBlackBoard )
            return -1;
    }
    pProc->m_iProcNo = getFirstAvailSlot();
    if ( pProc->m_iProcNo > HttpGlobals::s_children )
        return -1;
    preFork();
    pProc->m_pid = fork();
    if ( pProc->m_pid == -1 )
    {
        forkError( errno );
        return -1;
    }
    if ( pProc->m_pid == 0 )
    {   //child process
        cpu_set_t       cpu_affinity;
        
        if ( LsiApiHooks::getServerHooks()->isEnabled( LSI_HKPT_WORKER_POSTFORK) )
            LsiApiHooks::getServerHooks()->runCallbackNoParam(LSI_HKPT_WORKER_POSTFORK, NULL);

        PCUtil::getAffinityMask( s_iCpuCount, pProc->m_iProcNo-1, 1, &cpu_affinity );
        PCUtil::setCpuAffinity( &cpu_affinity );
        m_pServer->setBlackBoard( pProc->m_pBlackBoard );
        m_pServer->setProcNo( pProc->m_iProcNo );
        //setAffinity( 0, pProc->m_iProcNo);  //FIXME: need uncomment and debug
        releaseExcept( pProc );
        m_pServer->reinitMultiplexer();
        close( m_fdAdmin );
        snprintf( argv0, 80, "openlitespeed (lshttpd - #%02d)", pProc->m_iProcNo );
        return 0;
    }
    
    if ( LsiApiHooks::getServerHooks()->isEnabled( LSI_HKPT_MAIN_POSTFORK) )
        LsiApiHooks::getServerHooks()->runCallbackNoParam(LSI_HKPT_MAIN_POSTFORK, NULL);
    postFork( pProc->m_pid );
    m_childrenList.push( pProc );
    pProc->m_iState = CP_RUNNING;
    setChildSlot( pProc->m_iProcNo, 1 );
    
    ++m_curChildren;
    return pProc->m_pid;
}