Exemple #1
0
void ACEApp::write_pid_file()
{
    string pid_file_path = program_;
    pid_file_path += ".pid";
    pid_file_path = "./" + pid_file_path;
    
    ACE_DEBUG((LM_INFO, "[%D] write pid file %s\n", pid_file_path.c_str()));
    
    ofstream pid_file(pid_file_path.c_str());
    pid_file << ACE_OS::getpid();
    pid_file.close();
}
bool Sentinel::is_process_dead(const std::string& pid_path) {
    std::ifstream pid_file(pid_path.c_str());
    if (pid_file.fail())
        return false;  // if pid file does not exist, the process was most
                       // likely intentionally stopped, report no issues

    std::string pid_str;
    std::getline(pid_file, pid_str);
    pid_file.close();
    int pid;
    try {
        pid = std::stoi(pid_str);
    } catch (const std::invalid_argument&) {
        return true;
    } catch (const std::out_of_range&) {
        return true;
    }
    // sending the ``0`` signal to any pid just checks if the process is alive
    return kill(pid, SIGNAL_CHECK) != ALIVE;
}