Ejemplo n.º 1
0
        int killDb( int port, pid_t _pid, int signal ) {
            pid_t pid;
            int exitCode = 0;
            if ( port > 0 ) {
                if( dbs.count( port ) != 1 ) {
                    cout << "No db started on port: " << port << endl;
                    return 0;
                }
                pid = dbs[ port ].first;
            }
            else {
                pid = _pid;
            }

            kill_wrapper( pid, signal, port );

            int i = 0;
            for( ; i < 130; ++i ) {
                if ( i == 30 ) {
                    char now[64];
                    time_t_to_String(time(0), now);
                    now[ 20 ] = 0;
                    cout << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl;
                    kill_wrapper( pid, SIGKILL, port );
                }
                if(wait_for_pid(pid, false, &exitCode))
                    break;
                sleepmillis( 1000 );
            }
            if ( i == 130 ) {
                char now[64];
                time_t_to_String(time(0), now);
                now[ 20 ] = 0;
                cout << now << " failed to terminate process on port " << port << ", with pid " << pid << endl;
                assert( "Failed to terminate process" == 0 );
            }

            if ( port > 0 ) {
                close( dbs[ port ].second );
                dbs.erase( port );
            }
            else {
                close( shells[ pid ] );
                shells.erase( pid );
            }
            // FIXME I think the intention here is to do an extra sleep only when SIGKILL is sent to the child process.
            // We may want to change the 4 below to 29, since values of i greater than that indicate we sent a SIGKILL.
            if ( i > 4 || signal == SIGKILL ) {
                sleepmillis( 4000 ); // allow operating system to reclaim resources
            }

            return exitCode;
        }
Ejemplo n.º 2
0
       int killDb( int port, pid_t _pid, int signal, const BSONObj& opt ) {
            pid_t pid;
            int exitCode = 0;
            if ( port > 0 ) {
                if( !registry.isPortRegistered( port ) ) {
                    log() << "No db started on port: " << port << endl;
                    return 0;
                }
                pid = registry.pidForPort( port );
            }
            else {
                pid = _pid;
            }

            kill_wrapper( pid, signal, port, opt );

            int i = 0;
            for( ; i < 130; ++i ) {
                if ( i == 60 ) {
                    char now[64];
                    time_t_to_String(time(0), now);
                    now[ 20 ] = 0;
                    log() << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl;
                    kill_wrapper( pid, SIGKILL, port, opt );
                }
                if(wait_for_pid(pid, false, &exitCode))
                    break;
                sleepmillis( 1000 );
            }
            if ( i == 130 ) {
                char now[64];
                time_t_to_String(time(0), now);
                now[ 20 ] = 0;
                log() << now << " failed to terminate process on port " << port << ", with pid " << pid << endl;
                verify( "Failed to terminate process" == 0 );
            }

            if ( port > 0 ) {
                registry.deletePort( port );
            }
            else {
                registry.deletePid( pid );
            }
            // FIXME I think the intention here is to do an extra sleep only when SIGKILL is sent to the child process.
            // We may want to change the 4 below to 29, since values of i greater than that indicate we sent a SIGKILL.
            if ( i > 4 || signal == SIGKILL ) {
                sleepmillis( 4000 ); // allow operating system to reclaim resources
            }

            return exitCode;
        }
Ejemplo n.º 3
0
        int killDb( int port, pid_t _pid, int signal ) {
            pid_t pid;
            int exitCode = 0;
            if ( port > 0 ) {
                if( dbs.count( port ) != 1 ) {
                    cout << "No db started on port: " << port << endl;
                    return 0;
                }
                pid = dbs[ port ].first;
            } else {
                pid = _pid;
            }
            
            kill_wrapper( pid, signal, port );
            
            int i = 0;
            for( ; i < 130; ++i ) {
                if ( i == 30 ) {
                    char now[64];
                    time_t_to_String(time(0), now);
                    now[ 20 ] = 0;
                    cout << now << " process on port " << port << ", with pid " << pid << " not terminated, sending sigkill" << endl;
                    kill_wrapper( pid, SIGKILL, port );
                }        
                if(wait_for_pid(pid, false, &exitCode))
                    break;
                sleepmillis( 1000 );
            }
            if ( i == 65 ) {
                char now[64];
                time_t_to_String(time(0), now);
                now[ 20 ] = 0;
                cout << now << " failed to terminate process on port " << port << ", with pid " << pid << endl;
                assert( "Failed to terminate process" == 0 );
            }

            if ( port > 0 ) {
                close( dbs[ port ].second );
                dbs.erase( port );
            } else {
                close( shells[ pid ] );
                shells.erase( pid );
            }
            if ( i > 4 || signal == SIGKILL ) {
                sleepmillis( 4000 ); // allow operating system to reclaim resources
            }
            
            return exitCode;
        }
Ejemplo n.º 4
0
int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) {
    ProcessId pid;
    if (port > 0) {
        if (!registry.isPortRegistered(port)) {
            log() << "No db started on port: " << port;
            return 0;
        }
        pid = registry.pidForPort(port);
    } else {
        pid = _pid;
    }

    kill_wrapper(pid, signal, port, opt);

    int exitCode = EXIT_FAILURE;
    try {
        wait_for_pid(pid, true, &exitCode);
    } catch (...) {
        warning() << "process " << pid << " failed to terminate.";
        return EXIT_FAILURE;
    }

    if (signal == SIGKILL) {
        sleepmillis(4000);  // allow operating system to reclaim resources
    }

    return exitCode;
}
Ejemplo n.º 5
0
int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) {
    ProcessId pid;
    int exitCode = 0;
    if (port > 0) {
        if (!registry.isPortRegistered(port)) {
            log() << "No db started on port: " << port;
            return 0;
        }
        pid = registry.pidForPort(port);
    } else {
        pid = _pid;
    }

    kill_wrapper(pid, signal, port, opt);

    bool processTerminated = false;
    bool killSignalSent = (signal == SIGKILL);
    for (int i = 0; i < 1300; ++i) {
        if (i == 600) {
            log() << "process on port " << port << ", with pid " << pid
                  << " not terminated, sending sigkill";
            kill_wrapper(pid, SIGKILL, port, opt);
            killSignalSent = true;
        }
        processTerminated = wait_for_pid(pid, false, &exitCode);
        if (processTerminated) {
            break;
        }
        sleepmillis(100);
    }
    if (!processTerminated) {
        severe() << "failed to terminate process on port " << port << ", with pid " << pid;
        invariant(false);
    }

    registry.deleteProgram(pid);

    if (killSignalSent) {
        sleepmillis(4000);  // allow operating system to reclaim resources
    }

    return exitCode;
}