Re: safe shut-down

In other words, consider trapping the TERM and KILL signals instead, doing
a fast clean-up (no asking questions) and then exit.

Havoc Pennington wrote:

Carlos Pereira <carlos pehoe civil ist utl pt> writes:
My app must be close with the close button (x button).
If the user launches the app in a console, he can close it
with crtl+c and this produces a non-safe shut-down.
How can I avoid this?

#include <signal.h>

/* to disable crtl+c */
signal (SIGINT, SIG_IGN);

/* to enable crtl+c */
signal(SIGINT, SIG_DFL);

This is AINSI C code, so it should really work everywhere.

Of course the user can still kill -9, and your app can still crash, so
you probably don't want to depend on disabling Ctrl-C.

Michael T. Babcock, C.T.O. FibreSpeed

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]