Termination

1998-06-16 Thread James
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

Re: Termination

1998-06-16 Thread John Gorman
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() {

Re: Termination

1998-06-16 Thread Marin D
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

Re: Termination

1998-06-16 Thread Pawel S. Veselov
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,

Re: Termination

1998-06-16 Thread Glynn Clements
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,

Re: Termination

1998-06-16 Thread Glynn Clements
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]