Пример #1
0
void
RSIM_Simulator::terminate_self()
{
    RSIM_Process *process = get_process();
    if (!process->has_terminated())
        return;

    SAWYER_THREAD_TRAITS::RecursiveLockGuard lock(class_rwlock);
    int status = process->get_termination_status();
    if (WIFEXITED(status)) {
        exit(WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
        struct sigaction sa, old;
        memset(&sa, 0, sizeof sa);
        sa.sa_handler = SIG_DFL;
        sigaction(WTERMSIG(status), &sa, &old);
        raise(WTERMSIG(status));
        sigaction(WTERMSIG(status), &old, NULL);
    } else if (WIFSTOPPED(status)) {
        struct sigaction sa, old;
        memset(&sa, 0, sizeof sa);
        sa.sa_handler = SIG_DFL;
        sigaction(WTERMSIG(status), &sa, &old);
        raise(WTERMSIG(status));
        sigaction(WTERMSIG(status), &old, NULL);
    }
}
Пример #2
0
std::string
RSIM_Simulator::describe_termination()
{
    std::ostringstream m;
    RSIM_Process *process = get_process();
    if (process->has_terminated()) {
        int status = process->get_termination_status();
        if (WIFEXITED(status)) {
            mfprintf(m)("specimen %d exited with status %d", getpid(), WEXITSTATUS(status));
        } else if (WIFSIGNALED(status)) {
            mfprintf(m)("specimen %d exited due to signal %s %s",
                        getpid(), strsignal(WTERMSIG(status)), WCOREDUMP(status)?" core dumped":"");
        } else if (WIFSTOPPED(status)) {
            mfprintf(m)("specimen %d is stopped due to signal %s", getpid(), strsignal(WSTOPSIG(status)));
        } else {
            mfprintf(m)("specimen %d has unknown termination status: 0x%08x", getpid(), status);
        }
    } else {
        mfprintf(m)("specimen %d has not exited yet", getpid());
    }
    return m.str();
}