I have automated tests for fairly complex software, which send SIGQUIT signals at program startup. If the signal arrives before the handler is installed, a coredump is generated, causing the test to fail.

An example program is provided below.

Even if we install the handler as the first line of the program, we could still potentially get a crashdump. Is there a way to install a SIGQUIT handler so that crashdumps are never generated?

void sigquit(int signo)
{
    _exit(0);
}

int main()
{
    print("Hello");

    signal(SIGQUIT,sigquit)

    for(;;);
    return 0;
}

7 Replies 7

You could call the program by a wrapper like a shell script using trap to ignore SIGQUIT. Of course no handler function would be caused in that scenario if the signal arrived before the handler was istalled but at least no core dump either

Is the goal to prevent the generation of dumps or to prevent the premature termination of the program? Are you saying that automated tests report failure because they see a dump generated, not because the program terminated prematurely?

Can you explain why these automated tests are sending your program SIGQUIT in the first place, please? Normally, automated requests for a process to shut down cleanly as soon as possible should use SIGTERM, not SIGQUIT.

The default action for SIGQUIT per POSIX has been to terminate the process with "addtional actions" since at least 1990. Those "additional actions" are usually implemented as "generate a core file".

SIGTERM is meant to signal a process that it should terminate, and it does not result in any "additional actions" such as core file generation. SIGINT is meant to terminate a process, too, but in the context of a keyboard-generated interrupt.

In other words, you're trying use a hammer to drive in a wood screw. Yes, it "works", but it has unwanted side effects. The fix it to use a screw driver and not a hammer.

Just use SIGTERM.

I echo everybody above in saying "why are you using SIGQUIT?

In any event, whether the core is dumped or not is a function of the operating system and varies accordingly. If you really really do want to send SIGQUIT, it might be easier to have your test clean up the core afterwards, rather than prevent it from happening.

... in particular, various ways to prevent core dumps from being generated on Linux are documented in the core entry in section 5 of the manual. If you're in fact on Linux then the alternatives based on setting resource limits are probably the first thing you should consider.

You can stop programs from actually dumping core by setting ulimit -c 0 in the shell and then running the tests. That sets the core dump size to 0. You still get the message "dumping core", but no core dump is actually generated. This has the advantage that the setting is in place before the program runs. It does assume that the test suite does not reset the limit.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.