is it possible to have a function called when the user presses ^C or kills
the program so that the program can 'clean up' before being terminated? (i.e
close all open files, write out data, free allocated memory etc). if so, how?
-[[EMAIL
Hi,
Sure you just need to have a signal handler in your program.
For instance:
#include signal.h
int catch_signal(); /* Prototype function */
int main()
{
.
.
.
/*
* Setup to catch interrupt (^C)
*/
signal(SIGINT, catch_signal);
.
.
} /* END: main() */
int catch_signal()
{
On Tue, 16 Jun 1998, James wrote:
is it possible to have a function called when the user presses ^C or kills
^C generates SIGINT so u may catch it by sigaction()/signal()
SIGKILL cannot be caught so if your process is kill-ed it has no chance of
cleaning after itself. Cleanup routines
Hello, James!
On Tue, 16 Jun 1998, James wrote:
is it possible to have a function called when the user presses ^C or kills
the program so that the program can 'clean up' before being terminated? (i.e
close all open files, write out data, free allocated memory etc). if so,
James wrote:
is it possible to have a function called when the user presses ^C or kills
the program so that the program can 'clean up' before being terminated? (i.e
close all open files, write out data, free allocated memory etc). if so, how?
Use sigaction() to install a handler for SIGINT,
Marin D wrote:
void handle_sigint()
{
/* your cleanup code */
printf("Doing cleanup\n");
fflush(stdout);
The stdio functions aren't guaranteed to be re-entrant, so they
shouldn't be called from within a signal handler.
--
Glynn Clements [EMAIL PROTECTED]