INT32 iPmdDMNChildProc::stop() { if ( NULL != _procInfo ) { INT32 tryTimes = 0; BOOLEAN isForce = FALSE ; INT32 waitTimes = PMD_QUIT_CHL_WAIT_TIMES ; while( isChildRunning() ) { ++waitTimes ; if ( tryTimes++ >= PMDDMN_STOP_CHILD_MAX_TRY_TIMES ) { isForce = TRUE ; } if ( OSS_INVALID_PID != _pid ) { if ( !isForce && _procInfo ) { if ( waitTimes >= PMD_QUIT_CHL_WAIT_TIMES ) { _procInfo->stat = PMDDMN_SHM_STAT_CHILDREN ; _procInfo->setCHLCMD( PMDDMN_SHM_CMD_CHL_QUIT ) ; waitTimes = 0 ; #if defined ( _LINUX ) ossTerminateProcess( _pid, FALSE ) ; #endif // _LINUX PD_LOG( PDEVENT, "stop the service process(%d)...", _pid ) ; } } else { ossTerminateProcess( _pid, isForce ) ; PD_LOG( PDEVENT, "Terminate the service process(%d)...", _pid ) ; } } else if ( tryTimes >= PMDDMN_STOP_CHILD_MAX_TRY_TIMES ) { break; } ossSleep( OSS_ONE_SEC ) ; } } return fini() ; }
INT32 _spdFMP::quit( pmdEDUCB *cb ) { INT32 rc = SDB_OK ; BSONObj res ; rc = write( QUIT_MSG ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to write reset msg:%d", rc ) ; goto error ; } rc = read( res, cb, FALSE ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to read reset res:%d" ", kill process[%d]", rc, _id ) ; ossTerminateProcess( _id, TRUE ) ; } /// parse res obj if necessary in future. ossCloseNamedPipe( _in ) ; ossCloseNamedPipe( _out ) ; #if defined (_WINDOWS) rc = ossWaitInterrupt( (HANDLE)_id, 10000 ) ; #elif defined (_LINUX) { ossResultCode result ; rc = ossWaitChild( _id, result ) ; } #endif if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to wait child process[%d], rc:%d", _id, rc ) ; goto error ; } _id = -1 ; done: return rc ; error: goto done ; }
_spdFMP::~_spdFMP() { if ( -1 != _id ) { ossCloseNamedPipe( _in ) ; ossCloseNamedPipe( _out ) ; ossTerminateProcess( _id, TRUE ) ; #if defined (_WINDOWS) ossWaitInterrupt( (HANDLE)_id, 10000 ) ; #elif defined (_LINUX) ossResultCode result ; ossWaitChild( _id, result ) ; #endif } if ( NULL != _readBuf ) { SDB_OSS_FREE( _readBuf ) ; } }